Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8272697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T07:13:01+00:00 2026-06-08T07:13:01+00:00

So, I’m working on a Pybrain-type project and I’m stuck on part of it.

  • 0

So, I’m working on a Pybrain-type project and I’m stuck on part of it.
So far the program takes in a tuple and assigns a variable to it using ‘one of them fancy vars()['string'] statements. Specifically, it takes in a tuple of numbers and assigns it to a ‘layerx‘ value, where x is the number of the layer (in order, layer 1, 2, 3, etc), such that the numbers are the dimensions of that layer.

The part of the program I desperately and humbly come to you for help in is what should be the next step in the program; it takes in a tuple of tuples (the number of tuples must = the number of layers), and the tuples contain 1/0’s.

It is supposed to determine what type of Pybrain Layer to use in what layer, and then plugs in that layer’s dimension value and, essentially, creates that layer-variable. I’ve…played with it for a while, and I’ve gotten a really…twisted…confusing block of code.

Please pardon the convoluted variable names, I thought I was being smart by making them somewhat specific:

    moduleconbuff = 0
    modulebuffer = 'module'
    correspondinglayerbuff = 0
    moduleconfigcopy = tuple(moduleconfig)

    try:  #Always triggers except, but it's pretty screwed up
                while correspondinglayerbuff <= len(self.layers):     #keeps track of how many layer/module pairs have been assigned
                    for elm in moduleconfigcopy:
                        for x in elm:
                            if x == 1:
                                moduledimmension = [layerbuff+'%s'%(correspondinglayerbuff)]
                                modulesdict = {1: pybrain.GaussianLayer(moduledimmension), 2: pybrain.LinearLayer(moduledimmension),\
                                3: pybrain.LSTMLayer(moduledimmension),4: pybrain.SigmoidLayer(moduledimmension),5: pybrain.TanhLayer(moduledimmension)}   #this dict pairs integers with pybrain modules
                                vars()[modulebuffer +'%s'%(correspondinglayerbuff)]=modulesdict(moduleconbuff)  #should return something like 'Module1 = pybrain.GaussianLayer(5) when complete
                                print vars()[modulebuffer+'%s'%(correspondinglayerbuff)]
                                moduleconbuff=0
                                correspondinglayerbuff+=1
                                print 'Valid: ', moduleconfigcopy, elm
                                continue
                            else:
                                elm = elm[1:]
                                print 'Invalid: ', moduleconfigcopy, elm
                                moduleconbuff+=1
    except:  
        print 'Invalid!!!'

I honestly lost track of what was going on in it. The tuple “moduleconfig” in the beginning
was supposed to be a tuple of tuples (nested tuples) with binary operators, it was supposed to stop when one of the tuples has a 1, match that operator with the right module in Pybrain, and then plug this in so the corresponding layer = that module with the dimmensions already listed.

Obviously something went terribly wrong, and it’s so fargone that my brain can’t make any sense of it…it’s lost all it’s reason and every time I look at it I get scared…please help me or tell me I created an abomination or something, I guess…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T07:13:03+00:00Added an answer on June 8, 2026 at 7:13 am

    One huge hindrance that’s affecting code readability for you is variable naming and style. I’ve tried to clean it up a little bit for you. It still might not work, but now it’s a LOT easier to see what’s going on. Please refer to PEP 8, the Python style guide

    For starters, I renamed some variables, below. Note that in python, variables should be all lowercase, with separate words connected by an underscore. Constants should be ALL_UPPERCASE:

    assigned_layers = correspondinglayerbuff = 0
    tuple_of_tuples = moduleconfigcopy = ((0, 1), (0, 0, 1), (0, 1))
    dimension = moduledimension
    MOD_BUFFER = modulebuffer = 'buffer'
    c_buff = moduleconbuff = 0
    

    And here is the while loop (with variable names replaced, and properly indented, with the try... except block removed:

    while assigned_layers <= len(self.layers):
        for element_tuple in tuple_of_tuples:
            for item in element_tuple:
                if item: # in python, 0 is treated as boolean False, 1 or any other value is treated as boolean True.
                    dimension = [layerbuff + str(assigned_layers)] #what is layerbuff?
                    modules_dict = {
                        1: pybrain.GaussianLayer(dimension),
                        2: pybrain.LinearLayer(dimension),
                        3: pybrain.LSTMLayer(dimension),
                        4: pybrain.SigmoidLayer(dimension),
                        5: pybrain.TanhLayer(dimension)
                        } # Notice how this dict is much easier to read.
    
                    vars()[MOD_BUFFER + str(assigned_layers)] = modules_dict[c_buff]  #modules_dict is a dict and not a callable object
                    c_buff = 0
                    assigned_layers +=1
                    #No need for continue here, since that's what the if...else does here.
                else:
                    element_tuple = element_tuple[1:] #what is this for?
                    print 'Invalid: ', tuple_of_tuples, element_tuple
    

    I’m not sure exactly what you are trying to do in this line:

    vars()[MOD_BUFFER + str(assigned_layers)] = modules_dict[c_buff]  #modules_dict is a dict and not a callable object
    

    Also, you originally had modules_dict(moduleconbuff) which will raise a TypeError as a dict is not a callable object. I’m assuming you meant to retrieve a value by key.

    As I said, I’m not quite sure what your trying to do here (probably because I haven’t seen the rest of your code), but renaming your variables and using good style should go a long way towards you being able to debug your code. I will continue to edit if you answer my questions/comment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm making a simple page using Google Maps API 3. My first. One marker
I am reading a book about Javascript and jQuery and using one of the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am using JSon response to parse title,date content and thumbnail images and place
I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I am using the SimpleRSS gem to parse a WordPress RSS feed. The only
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.