Like Tree2Likes

Program that can write its own code in C++

This is a discussion on Program that can write its own code in C++ within the C++ Programming forums, part of the General Programming Boards category; So let's start with Code: const int MAX_NEURONS = 10; neurontype neurons[MAX_NEURONS]; for ( i = 0 ; i < ...

  1. #16
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    So let's start with
    Code:
    const int MAX_NEURONS = 10;
    neurontype neurons[MAX_NEURONS];
    for ( i = 0 ; i < MAX_NEURONS ; i++ ) evalneuron(neurons[i]);
    As an alternative to
    Code:
    neurontype n1,n2,n3,n4,n5,n6,n7,n8,n9,n10;
    evalneuron(n1);
    evalneuron(n2);
    evalneuron(n3);
    evalneuron(n4);
    evalneuron(n5);
    evalneuron(n6);
    evalneuron(n7);
    evalneuron(n8);
    evalneuron(n9);
    evalneuron(n10);
    Now, changing the first one to process 20 neurons is as simple as changing 10 into 20.
    Changing the first one to process a number specified by the user at runtime is very easy.

    Doing either of these things with the second code involves massive code edits in the first instance, and is basically impossible in the second.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  2. #17
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,430
    Quote Originally Posted by Vacrin View Post
    Henry Markram: A brain in a supercomputer | Video on TED.com

    Here is where i got it, i suggest watching it
    Reading the synopsis, that is a project to "model components of the mammalian brain to precise cellular detail". Elkvis is talking about the concept of neural networks in software that is inspired by the neural networks in "the mammalian brain". The former is a specific project that has little to do with a "program that can write its own code in C++" (modeling cellular replication does not have to require such a property of a program); the latter is more in the realm of (traditional) AI.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #18
    Registered User
    Join Date
    Oct 2012
    Posts
    9
    Quote Originally Posted by Salem View Post
    So let's start with
    Code:
    const int MAX_NEURONS = 10;
    neurontype neurons[MAX_NEURONS];
    for ( i = 0 ; i < MAX_NEURONS ; i++ ) evalneuron(neurons[i]);
    As an alternative to
    Code:
    neurontype n1,n2,n3,n4,n5,n6,n7,n8,n9,n10;
    evalneuron(n1);
    evalneuron(n2);
    evalneuron(n3);
    evalneuron(n4);
    evalneuron(n5);
    evalneuron(n6);
    evalneuron(n7);
    evalneuron(n8);
    evalneuron(n9);
    evalneuron(n10);
    Now, changing the first one to process 20 neurons is as simple as changing 10 into 20.
    Changing the first one to process a number specified by the user at runtime is very easy.

    Doing either of these things with the second code involves massive code edits in the first instance, and is basically impossible in the second.

    referring to the top one, i would like a program that doesnt have a set number, so i think it should be possible if the program meets some kind of requirements to change the 10 into an variable and then whenever the program runs it can keep adding onto itself. However does eval allow me to create different kinds of if's and for's and while's within each of the evalneurons?
    guess to word that simpler, can i put code inside each evalneuron?

    Well the point of my idea of creating neurons is so that i can eventually simulate the brain or recreate the structure of a brain and then hopefully bring the neurons to life and see what happens as they make new connections and "learn". and so the idea of being able to write a program that can write its own code is my version of trying to some day bring a computer to life. the reason i want a program to be able to write itself is so that it can come up with its own idea of neuron paths and then make those as well re-code its self to be even smarter. however this is way down the line, in a time in which the computers will be powerful for such a massive "program".

    I don't plan on make this any day soon, but i figure i might as well get started early

  4. #19
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,451
    > so i think it should be possible if the program meets some kind of requirements to change the 10 into an variable and then whenever the program runs it can keep adding onto itself.
    No problem with that.
    Just have one of
    std::vector<neurontype> neurons;
    std::list<neurontype> neurons;

    and you can have an expanding or contracting number of neurons as you go.

    > guess to word that simpler, can i put code inside each evalneuron?
    You can make it do whatever you want, based on whatever instance data each neuron contains.

    Polymorphism - C++ Documentation
    Your list of neurons can be just a base class common to all neurons, but each derived class of specialised neurons can have it's own implementation of evalneuron for each specific kind of neuron you want to simulate.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #20
    Registered User
    Join Date
    Jun 2005
    Posts
    6,205
    Quote Originally Posted by Vacrin View Post
    referring to the top one, i would like a program that doesnt have a set number, so i think it should be possible if the program meets some kind of requirements to change the 10 into an variable and then whenever the program runs it can keep adding onto itself.
    It is possible to dynamically resize a standard container, such as a vector. For example;
    Code:
    #include <iostream>
    #include <vector>
    //   declarations of neurontype here
    int main()
    {
         int number;
         
         std::cin >> number;   //  read number from stdin
         std::vector<neurontype> neurons(number);
    
         int newnumber;
         std::cin >> newnumber;
    
         neurons.resize(newnumber);
    
         for (int i = 0; i < newnumber; ++i)   do_something(neuron[i]);
    }
    Quote Originally Posted by Vacrin View Post
    However does eval allow me to create different kinds of if's and for's and while's within each of the evalneurons?
    guess to word that simpler, can i put code inside each evalneuron?
    You're mixing concepts here very badly.

    For example, you need to distinguish between behaviour of a neuron that depends on some parameter, and the behaviour that different types of neurons have.

    There is a difference between saying "if neuron A is given stimulus with value X, then it does action Y" and "if any neuron type of type T is given a stimulus S, then it performs action Z".

    The first type of logic can be implemented by testing variables (normal program control structures like if statements and loop constructs). The second type of logic can be implemented in functions that affect all neurons of type T, but not neurons of type W (eg member functions of class named T).

    Quote Originally Posted by Vacrin View Post
    Well the point of my idea of creating neurons is so that i can eventually simulate the brain or recreate the structure of a brain and then hopefully bring the neurons to life and see what happens as they make new connections and "learn". and so the idea of being able to write a program that can write its own code is my version of trying to some day bring a computer to life. the reason i want a program to be able to write itself is so that it can come up with its own idea of neuron paths and then make those as well re-code its self to be even smarter. however this is way down the line, in a time in which the computers will be powerful for such a massive "program".
    What you are trying to do does not require a program that can write its own code. It requires a program that is structured in a way so it can adapt the behaviour of objects it models (or represents) based on inputs and outputs.

    Quote Originally Posted by Vacrin View Post
    I don't plan on make this any day soon, but i figure i might as well get started early
    I suggest you're jumping the gun with your dream.

    I suspect the basic ideas you have can be implemented without too much trouble in any programming language. However, you need to describe your model (how neurons work, how they interact, etc) much more precisely. Then you need to translate that description into code (in your selected language). That requires more knowledge of software engineering, and of C++ (if you choose to use C++), than you have. You therefore also need to spend some time learning the basics of C++ (or whatever language you choose to use), without thinking about neurons. Learn how to map ideas from what you might write on paper into something that can be implemented in code.
    laserlight likes this.
    Right 98% of the time, and don't care about the other 3%.

  6. #21
    Registered User
    Join Date
    Oct 2012
    Posts
    9
    Sorry my idea of programming and concepts is a still very crude because i'm trying to transfer over from using Logic gates to do tasks to using code.

    I would like to try the first one the "if neuron A is given stimulus with value X, then it does action Y" after i figure out how do such a thing.

    Im guessing i need adaptive code then? or something along those lines.

    I could be jumping the gun on my idea.

    I may not have the exact idea about how neurons work, but ive got a fairly good idea and im also getting a book that goes over the "workings" of a neuron. I think the description into code wont be that hard, but the knowledge of the language is the hard part for me at the moment.

  7. #22
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,430
    Maybe you should just get started with learning how to program then. If you want to use C++, then a book like Accelerated C++ would be a place to start.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  8. #23
    Registered User
    Join Date
    Jun 2005
    Posts
    6,205
    Quote Originally Posted by Vacrin View Post
    I would like to try the first one the "if neuron A is given stimulus with value X, then it does action Y" after i figure out how do such a thing.
    Firstly, you would need to characterise the stimulus, what its "value" is, and what action is required. The precise implementation then depends on how those things are described, but could well result in code that looks line
    Code:
       if (Stimulate(a_neuron, X)) PerformAction(a_neuron);
    Of course, the details of what is in the Stimulate() function, what type X is (an integer, a floating point variable, a compound type) and in the details of how PerformAction() is implemented.

    Quote Originally Posted by Vacrin View Post
    Im guessing i need adaptive code then? or something along those lines.
    You're just guessing. Just because the term "adaptive neural code" is used in literature about neurons, doesn't mean there is a similar concept in C++. And, in fact, there isn't. So you have to unambiguously specify how to implement that concept.

    Quote Originally Posted by Vacrin View Post
    I may not have the exact idea about how neurons work, but ive got a fairly good idea and im also getting a book that goes over the "workings" of a neuron. I think the description into code wont be that hard, but the knowledge of the language is the hard part for me at the moment.
    That is my point. You need to learn what software development is about. You're assuming that your imprecise description of neuron behaviour can be turned into code. Your assumption is incorrect. It is not possible to reliably create anything (be it a small bit of software or a skyscraper) unless you understand how to.
    Right 98% of the time, and don't care about the other 3%.

  9. #24
    Registered User
    Join Date
    Oct 2012
    Posts
    9
    True true grumpy. Alright well guess ill get started on learning a programming language. Thank you everyone

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What are you using to write your code?
    By Sjvlsdsd in forum General Discussions
    Replies: 21
    Last Post: 07-23-2011, 07:20 AM
  2. How to write basic code
    By tingting in forum C Programming
    Replies: 13
    Last Post: 07-22-2009, 04:16 PM
  3. how to write save code?
    By sept in forum C++ Programming
    Replies: 6
    Last Post: 09-18-2007, 07:25 AM
  4. How do I write more efficient code?
    By minesweeper in forum C++ Programming
    Replies: 4
    Last Post: 08-06-2002, 11:08 AM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21