Skip to main content
The 2024 Developer Survey results are live! See the results
added 143 characters in body
Source Link

EDIT

Sadly I optimized this code:( made it 2000x faster... The legacy code is still perfect for wasting time though!

Original

EDIT

Sadly I optimized this code:( made it 2000x faster... The legacy code is still perfect for wasting time though!

Original

deleted 4 characters in body
Source Link

This hasn't even finished yet for me, and it's been running for almost 21 hoursover 2 days! Then once we get that output, let's run it through again in reverse just for fun.

This hasn't even finished yet for me, and it's been running for almost 21 hours! Then once we get that output, let's run it through again in reverse just for fun.

This hasn't even finished yet for me, and it's been running for over 2 days! Then once we get that output, let's run it through again in reverse just for fun.

syntax highlighting added
Source Link
avall
  • 1.6k
  • 1
  • 10
  • 17
std::vector<int> numNeurons = { 500, 500, 2000, 10 };
std::vector<int> numMaps = { 1, 1, 1, 1 };

ConvolutionalNeuralNetwork neuralNetwork(numNeurons, numMaps, numNeurons, 
    std::vector<std::vector<int>>(), std::vector<std::vector<int>>());
std::vector<int> numNeurons = { 500, 500, 2000, 10 };
std::vector<int> numMaps = { 1, 1, 1, 1 };

ConvolutionalNeuralNetwork neuralNetwork(numNeurons, numMaps, numNeurons, 
    std::vector<std::vector<int>>(), std::vector<std::vector<int>>());
neuralNetwork.SaveToFile("test2.cnn");
neuralNetwork.SaveToFile("test2.cnn");
std::vector<std::vector<float>> input;
for (int i = 0; i < 2; ++i)
    input.push_back(std::vector<float>{});

for (int i = 0; i < 2; ++i)
    for (int j = 0; j < 3; ++j)
        input[i].push_back(rand() % 100);
neuralNetwork.SetInput(input);
std::vector<std::vector<float>> input;
for (int i = 0; i < 2; ++i)
    input.push_back(std::vector<float>{});

for (int i = 0; i < 2; ++i)
    for (int j = 0; j < 3; ++j)
        input[i].push_back(rand() % 100);
neuralNetwork.SetInput(input);
Layer output = neuralNetwork.Discriminate();
Layer output = neuralNetwork.Discriminate();
Layer generatedOutput = neuralNetwork.Generate(output);
Layer generatedOutput = neuralNetwork.Generate(output);
neuralNetwork.LearnCurrentInput();
neuralNetwork.LearnCurrentInput();
ConvolutionalNeuralNetwork::ConvolutionalNeuralNetwork(std::vector<int> neuronCountPerLayer, std::vector<int> featureMapsPerLayer, std::vector<int> featureMapDimensions, std::vector<std::vector<int>> featureMapConnections, std::vector<std::vector<int>> featureMapStartIndex)
{
std::map<SimpleNeuron, std::vector<Synapse>> childrenOf;
for (unsigned int i = 0; i < neuronCountPerLayer.size() - 1; ++i)
{
    Layer currentLayer;

    for (int j = 0; j < neuronCountPerLayer[i]; ++j)
    {
        std::vector<Synapse> parentOf;

        if (featureMapsPerLayer[i] == 1)
        {
            for (int n = 0; n < neuronCountPerLayer[i + 1]; ++n)
            {
                std::cout << "Adding new synapse, data: " << std::endl;
                
                SimpleNeuron current = SimpleNeuron(i + 1, j + 1);
                SimpleNeuron destination = SimpleNeuron(i + 2, n + 1);

                std::cout << "Origin: " << i + 1 << ", " << j + 1 << "; Destination: " << i + 2 << ", " << n + 1 << std::endl;

                Synapse currentParentSynapse = Synapse(current, current);
                Synapse currentChildSynapse = Synapse(destination, destination);

                currentChildSynapse.SetWeightDiscriminate(currentParentSynapse.GetWeightDiscriminate());
                currentChildSynapse.SetWeightGenerative(currentParentSynapse.GetWeightGenerative());

                std::cout << "Weights: Discriminative: " << currentChildSynapse.GetWeightDiscriminate() << "; Generative: " << currentChildSynapse.GetWeightGenerative() << std::endl;

                parentOf.push_back(currentParentSynapse);

                if (childrenOf.find(destination) != childrenOf.end())
                    childrenOf.at(destination).push_back(currentChildSynapse);
                else
                    childrenOf.insert(std::pair<SimpleNeuron, std::vector<Synapse>>(destination,
                    std::vector<Synapse>{ currentChildSynapse }));
            }
        }

        else
        {
            int featureMapsUp = featureMapsPerLayer[i + 1];
            int inFeatureMap = featureMapsPerLayer[i] / j;
            int connections = featureMapConnections[i][inFeatureMap];
            int startIndex = (neuronCountPerLayer[i + 1] / featureMapsUp) * featureMapStartIndex[i][inFeatureMap];
            int destinationIndex = startIndex + (neuronCountPerLayer[i + 1] / featureMapsUp) * connections;

            for (int n = startIndex; n < destinationIndex; ++n)
            {
                SimpleNeuron current = SimpleNeuron(i + 1, j + 1);
                SimpleNeuron destination = SimpleNeuron(i + 2, n + 1);

                std::cout << "Origin: " << i + 1 << ", " << j + 1 << "; Destination: " << i + 2 << ", " << n + 1 << std::endl;

                Synapse currentParentSynapse = Synapse(current, current);
                Synapse currentChildSynapse = Synapse(destination, destination);

                currentChildSynapse.SetWeightDiscriminate(currentParentSynapse.GetWeightDiscriminate());
                currentChildSynapse.SetWeightGenerative(currentParentSynapse.GetWeightGenerative());

                std::cout << "Weights: Discriminative: " << currentChildSynapse.GetWeightDiscriminate() << "; Generative: " << currentChildSynapse.GetWeightGenerative() << std::endl;

                parentOf.push_back(currentParentSynapse);

                if (childrenOf.find(destination) != childrenOf.end())
                    childrenOf.at(destination).push_back(currentChildSynapse);
                else
                    childrenOf.insert(std::pair<SimpleNeuron, std::vector<Synapse>>(destination,
                    std::vector<Synapse>{ currentChildSynapse }));
            }
        }

        std::cout << "Adding neuron" << std::endl << std::endl;

        if (childrenOf.find(SimpleNeuron(i + 1, j + 1)) != childrenOf.end())
            currentLayer.AddNeuron(Neuron(parentOf, childrenOf.at(SimpleNeuron(i + 1, j + 1))));
        else
            currentLayer.AddNeuron(Neuron(parentOf, std::vector<Synapse>{}));
    }
    
    std::cout << "Adding layer" << std::endl << std::endl << std::endl;

    AddLayer(currentLayer);
}

Layer output;

std::cout << "Adding final layer" << std::endl;

for (int i = 0; i < neuronCountPerLayer[neuronCountPerLayer.size() - 1]; ++i)
    output.AddNeuron(Neuron(std::vector<Synapse>(), childrenOf.at(SimpleNeuron(neuronCountPerLayer.size(), i + 1))));
AddLayer(output);
}
ConvolutionalNeuralNetwork::ConvolutionalNeuralNetwork(std::vector<int> neuronCountPerLayer, std::vector<int> featureMapsPerLayer, std::vector<int> featureMapDimensions, std::vector<std::vector<int>> featureMapConnections, std::vector<std::vector<int>> featureMapStartIndex)
{
std::map<SimpleNeuron, std::vector<Synapse>> childrenOf;
for (unsigned int i = 0; i < neuronCountPerLayer.size() - 1; ++i)
{
    Layer currentLayer;

    for (int j = 0; j < neuronCountPerLayer[i]; ++j)
    {
        std::vector<Synapse> parentOf;

        if (featureMapsPerLayer[i] == 1)
        {
            for (int n = 0; n < neuronCountPerLayer[i + 1]; ++n)
            {
                std::cout << "Adding new synapse, data: " << std::endl;
                
                SimpleNeuron current = SimpleNeuron(i + 1, j + 1);
                SimpleNeuron destination = SimpleNeuron(i + 2, n + 1);

                std::cout << "Origin: " << i + 1 << ", " << j + 1 << "; Destination: " << i + 2 << ", " << n + 1 << std::endl;

                Synapse currentParentSynapse = Synapse(current, current);
                Synapse currentChildSynapse = Synapse(destination, destination);

                currentChildSynapse.SetWeightDiscriminate(currentParentSynapse.GetWeightDiscriminate());
                currentChildSynapse.SetWeightGenerative(currentParentSynapse.GetWeightGenerative());

                std::cout << "Weights: Discriminative: " << currentChildSynapse.GetWeightDiscriminate() << "; Generative: " << currentChildSynapse.GetWeightGenerative() << std::endl;

                parentOf.push_back(currentParentSynapse);

                if (childrenOf.find(destination) != childrenOf.end())
                    childrenOf.at(destination).push_back(currentChildSynapse);
                else
                    childrenOf.insert(std::pair<SimpleNeuron, std::vector<Synapse>>(destination,
                    std::vector<Synapse>{ currentChildSynapse }));
            }
        }

        else
        {
            int featureMapsUp = featureMapsPerLayer[i + 1];
            int inFeatureMap = featureMapsPerLayer[i] / j;
            int connections = featureMapConnections[i][inFeatureMap];
            int startIndex = (neuronCountPerLayer[i + 1] / featureMapsUp) * featureMapStartIndex[i][inFeatureMap];
            int destinationIndex = startIndex + (neuronCountPerLayer[i + 1] / featureMapsUp) * connections;

            for (int n = startIndex; n < destinationIndex; ++n)
            {
                SimpleNeuron current = SimpleNeuron(i + 1, j + 1);
                SimpleNeuron destination = SimpleNeuron(i + 2, n + 1);

                std::cout << "Origin: " << i + 1 << ", " << j + 1 << "; Destination: " << i + 2 << ", " << n + 1 << std::endl;

                Synapse currentParentSynapse = Synapse(current, current);
                Synapse currentChildSynapse = Synapse(destination, destination);

                currentChildSynapse.SetWeightDiscriminate(currentParentSynapse.GetWeightDiscriminate());
                currentChildSynapse.SetWeightGenerative(currentParentSynapse.GetWeightGenerative());

                std::cout << "Weights: Discriminative: " << currentChildSynapse.GetWeightDiscriminate() << "; Generative: " << currentChildSynapse.GetWeightGenerative() << std::endl;

                parentOf.push_back(currentParentSynapse);

                if (childrenOf.find(destination) != childrenOf.end())
                    childrenOf.at(destination).push_back(currentChildSynapse);
                else
                    childrenOf.insert(std::pair<SimpleNeuron, std::vector<Synapse>>(destination,
                    std::vector<Synapse>{ currentChildSynapse }));
            }
        }

        std::cout << "Adding neuron" << std::endl << std::endl;

        if (childrenOf.find(SimpleNeuron(i + 1, j + 1)) != childrenOf.end())
            currentLayer.AddNeuron(Neuron(parentOf, childrenOf.at(SimpleNeuron(i + 1, j + 1))));
        else
            currentLayer.AddNeuron(Neuron(parentOf, std::vector<Synapse>{}));
    }
    
    std::cout << "Adding layer" << std::endl << std::endl << std::endl;

    AddLayer(currentLayer);
}

Layer output;

std::cout << "Adding final layer" << std::endl;

for (int i = 0; i < neuronCountPerLayer[neuronCountPerLayer.size() - 1]; ++i)
    output.AddNeuron(Neuron(std::vector<Synapse>(), childrenOf.at(SimpleNeuron(neuronCountPerLayer.size(), i + 1))));
AddLayer(output);
}
float Neuron::FireSynapse()
{
float sum = 0.0f;

std::cout << "Firing Synapse!" << std::endl;

for (std::vector<Synapse>::iterator it = m_ChildOfSynapses.begin(); it != m_ChildOfSynapses.end(); ++it)
    sum += ((*it).GetWeightDiscriminate() * (*it).GetParent().GetValue());

std::cout << "Total sum: " << sum << std::endl;

float probability = (1 / (1 + pow(e, -sum)));

std::cout << "Probably of firing: " << probability << std::endl;

if (probability > 0.9f)
    return 1.0f;

else if (probability < 0.1f)
    return 0.0f;

else
{
    std::cout << "Using stochastic processing to determine firing" << std::endl;
    float random = ((rand() % 100) / 100);
    if (random <= probability)
        return 1.0f;
    else
        return 0.0f;
}
}
float Neuron::FireSynapse()
{
float sum = 0.0f;

std::cout << "Firing Synapse!" << std::endl;

for (std::vector<Synapse>::iterator it = m_ChildOfSynapses.begin(); it != m_ChildOfSynapses.end(); ++it)
    sum += ((*it).GetWeightDiscriminate() * (*it).GetParent().GetValue());

std::cout << "Total sum: " << sum << std::endl;

float probability = (1 / (1 + pow(e, -sum)));

std::cout << "Probably of firing: " << probability << std::endl;

if (probability > 0.9f)
    return 1.0f;

else if (probability < 0.1f)
    return 0.0f;

else
{
    std::cout << "Using stochastic processing to determine firing" << std::endl;
    float random = ((rand() % 100) / 100);
    if (random <= probability)
        return 1.0f;
    else
        return 0.0f;
}
}
std::vector<int> numNeurons = { 500, 500, 2000, 10 };
std::vector<int> numMaps = { 1, 1, 1, 1 };

ConvolutionalNeuralNetwork neuralNetwork(numNeurons, numMaps, numNeurons, 
    std::vector<std::vector<int>>(), std::vector<std::vector<int>>());
neuralNetwork.SaveToFile("test2.cnn");
std::vector<std::vector<float>> input;
for (int i = 0; i < 2; ++i)
    input.push_back(std::vector<float>{});

for (int i = 0; i < 2; ++i)
    for (int j = 0; j < 3; ++j)
        input[i].push_back(rand() % 100);
neuralNetwork.SetInput(input);
Layer output = neuralNetwork.Discriminate();
Layer generatedOutput = neuralNetwork.Generate(output);
neuralNetwork.LearnCurrentInput();
ConvolutionalNeuralNetwork::ConvolutionalNeuralNetwork(std::vector<int> neuronCountPerLayer, std::vector<int> featureMapsPerLayer, std::vector<int> featureMapDimensions, std::vector<std::vector<int>> featureMapConnections, std::vector<std::vector<int>> featureMapStartIndex)
{
std::map<SimpleNeuron, std::vector<Synapse>> childrenOf;
for (unsigned int i = 0; i < neuronCountPerLayer.size() - 1; ++i)
{
    Layer currentLayer;

    for (int j = 0; j < neuronCountPerLayer[i]; ++j)
    {
        std::vector<Synapse> parentOf;

        if (featureMapsPerLayer[i] == 1)
        {
            for (int n = 0; n < neuronCountPerLayer[i + 1]; ++n)
            {
                std::cout << "Adding new synapse, data: " << std::endl;
                
                SimpleNeuron current = SimpleNeuron(i + 1, j + 1);
                SimpleNeuron destination = SimpleNeuron(i + 2, n + 1);

                std::cout << "Origin: " << i + 1 << ", " << j + 1 << "; Destination: " << i + 2 << ", " << n + 1 << std::endl;

                Synapse currentParentSynapse = Synapse(current, current);
                Synapse currentChildSynapse = Synapse(destination, destination);

                currentChildSynapse.SetWeightDiscriminate(currentParentSynapse.GetWeightDiscriminate());
                currentChildSynapse.SetWeightGenerative(currentParentSynapse.GetWeightGenerative());

                std::cout << "Weights: Discriminative: " << currentChildSynapse.GetWeightDiscriminate() << "; Generative: " << currentChildSynapse.GetWeightGenerative() << std::endl;

                parentOf.push_back(currentParentSynapse);

                if (childrenOf.find(destination) != childrenOf.end())
                    childrenOf.at(destination).push_back(currentChildSynapse);
                else
                    childrenOf.insert(std::pair<SimpleNeuron, std::vector<Synapse>>(destination,
                    std::vector<Synapse>{ currentChildSynapse }));
            }
        }

        else
        {
            int featureMapsUp = featureMapsPerLayer[i + 1];
            int inFeatureMap = featureMapsPerLayer[i] / j;
            int connections = featureMapConnections[i][inFeatureMap];
            int startIndex = (neuronCountPerLayer[i + 1] / featureMapsUp) * featureMapStartIndex[i][inFeatureMap];
            int destinationIndex = startIndex + (neuronCountPerLayer[i + 1] / featureMapsUp) * connections;

            for (int n = startIndex; n < destinationIndex; ++n)
            {
                SimpleNeuron current = SimpleNeuron(i + 1, j + 1);
                SimpleNeuron destination = SimpleNeuron(i + 2, n + 1);

                std::cout << "Origin: " << i + 1 << ", " << j + 1 << "; Destination: " << i + 2 << ", " << n + 1 << std::endl;

                Synapse currentParentSynapse = Synapse(current, current);
                Synapse currentChildSynapse = Synapse(destination, destination);

                currentChildSynapse.SetWeightDiscriminate(currentParentSynapse.GetWeightDiscriminate());
                currentChildSynapse.SetWeightGenerative(currentParentSynapse.GetWeightGenerative());

                std::cout << "Weights: Discriminative: " << currentChildSynapse.GetWeightDiscriminate() << "; Generative: " << currentChildSynapse.GetWeightGenerative() << std::endl;

                parentOf.push_back(currentParentSynapse);

                if (childrenOf.find(destination) != childrenOf.end())
                    childrenOf.at(destination).push_back(currentChildSynapse);
                else
                    childrenOf.insert(std::pair<SimpleNeuron, std::vector<Synapse>>(destination,
                    std::vector<Synapse>{ currentChildSynapse }));
            }
        }

        std::cout << "Adding neuron" << std::endl << std::endl;

        if (childrenOf.find(SimpleNeuron(i + 1, j + 1)) != childrenOf.end())
            currentLayer.AddNeuron(Neuron(parentOf, childrenOf.at(SimpleNeuron(i + 1, j + 1))));
        else
            currentLayer.AddNeuron(Neuron(parentOf, std::vector<Synapse>{}));
    }
    
    std::cout << "Adding layer" << std::endl << std::endl << std::endl;

    AddLayer(currentLayer);
}

Layer output;

std::cout << "Adding final layer" << std::endl;

for (int i = 0; i < neuronCountPerLayer[neuronCountPerLayer.size() - 1]; ++i)
    output.AddNeuron(Neuron(std::vector<Synapse>(), childrenOf.at(SimpleNeuron(neuronCountPerLayer.size(), i + 1))));
AddLayer(output);
}
float Neuron::FireSynapse()
{
float sum = 0.0f;

std::cout << "Firing Synapse!" << std::endl;

for (std::vector<Synapse>::iterator it = m_ChildOfSynapses.begin(); it != m_ChildOfSynapses.end(); ++it)
    sum += ((*it).GetWeightDiscriminate() * (*it).GetParent().GetValue());

std::cout << "Total sum: " << sum << std::endl;

float probability = (1 / (1 + pow(e, -sum)));

std::cout << "Probably of firing: " << probability << std::endl;

if (probability > 0.9f)
    return 1.0f;

else if (probability < 0.1f)
    return 0.0f;

else
{
    std::cout << "Using stochastic processing to determine firing" << std::endl;
    float random = ((rand() % 100) / 100);
    if (random <= probability)
        return 1.0f;
    else
        return 0.0f;
}
}
std::vector<int> numNeurons = { 500, 500, 2000, 10 };
std::vector<int> numMaps = { 1, 1, 1, 1 };

ConvolutionalNeuralNetwork neuralNetwork(numNeurons, numMaps, numNeurons, 
    std::vector<std::vector<int>>(), std::vector<std::vector<int>>());
neuralNetwork.SaveToFile("test2.cnn");
std::vector<std::vector<float>> input;
for (int i = 0; i < 2; ++i)
    input.push_back(std::vector<float>{});

for (int i = 0; i < 2; ++i)
    for (int j = 0; j < 3; ++j)
        input[i].push_back(rand() % 100);
neuralNetwork.SetInput(input);
Layer output = neuralNetwork.Discriminate();
Layer generatedOutput = neuralNetwork.Generate(output);
neuralNetwork.LearnCurrentInput();
ConvolutionalNeuralNetwork::ConvolutionalNeuralNetwork(std::vector<int> neuronCountPerLayer, std::vector<int> featureMapsPerLayer, std::vector<int> featureMapDimensions, std::vector<std::vector<int>> featureMapConnections, std::vector<std::vector<int>> featureMapStartIndex)
{
std::map<SimpleNeuron, std::vector<Synapse>> childrenOf;
for (unsigned int i = 0; i < neuronCountPerLayer.size() - 1; ++i)
{
    Layer currentLayer;

    for (int j = 0; j < neuronCountPerLayer[i]; ++j)
    {
        std::vector<Synapse> parentOf;

        if (featureMapsPerLayer[i] == 1)
        {
            for (int n = 0; n < neuronCountPerLayer[i + 1]; ++n)
            {
                std::cout << "Adding new synapse, data: " << std::endl;
                
                SimpleNeuron current = SimpleNeuron(i + 1, j + 1);
                SimpleNeuron destination = SimpleNeuron(i + 2, n + 1);

                std::cout << "Origin: " << i + 1 << ", " << j + 1 << "; Destination: " << i + 2 << ", " << n + 1 << std::endl;

                Synapse currentParentSynapse = Synapse(current, current);
                Synapse currentChildSynapse = Synapse(destination, destination);

                currentChildSynapse.SetWeightDiscriminate(currentParentSynapse.GetWeightDiscriminate());
                currentChildSynapse.SetWeightGenerative(currentParentSynapse.GetWeightGenerative());

                std::cout << "Weights: Discriminative: " << currentChildSynapse.GetWeightDiscriminate() << "; Generative: " << currentChildSynapse.GetWeightGenerative() << std::endl;

                parentOf.push_back(currentParentSynapse);

                if (childrenOf.find(destination) != childrenOf.end())
                    childrenOf.at(destination).push_back(currentChildSynapse);
                else
                    childrenOf.insert(std::pair<SimpleNeuron, std::vector<Synapse>>(destination,
                    std::vector<Synapse>{ currentChildSynapse }));
            }
        }

        else
        {
            int featureMapsUp = featureMapsPerLayer[i + 1];
            int inFeatureMap = featureMapsPerLayer[i] / j;
            int connections = featureMapConnections[i][inFeatureMap];
            int startIndex = (neuronCountPerLayer[i + 1] / featureMapsUp) * featureMapStartIndex[i][inFeatureMap];
            int destinationIndex = startIndex + (neuronCountPerLayer[i + 1] / featureMapsUp) * connections;

            for (int n = startIndex; n < destinationIndex; ++n)
            {
                SimpleNeuron current = SimpleNeuron(i + 1, j + 1);
                SimpleNeuron destination = SimpleNeuron(i + 2, n + 1);

                std::cout << "Origin: " << i + 1 << ", " << j + 1 << "; Destination: " << i + 2 << ", " << n + 1 << std::endl;

                Synapse currentParentSynapse = Synapse(current, current);
                Synapse currentChildSynapse = Synapse(destination, destination);

                currentChildSynapse.SetWeightDiscriminate(currentParentSynapse.GetWeightDiscriminate());
                currentChildSynapse.SetWeightGenerative(currentParentSynapse.GetWeightGenerative());

                std::cout << "Weights: Discriminative: " << currentChildSynapse.GetWeightDiscriminate() << "; Generative: " << currentChildSynapse.GetWeightGenerative() << std::endl;

                parentOf.push_back(currentParentSynapse);

                if (childrenOf.find(destination) != childrenOf.end())
                    childrenOf.at(destination).push_back(currentChildSynapse);
                else
                    childrenOf.insert(std::pair<SimpleNeuron, std::vector<Synapse>>(destination,
                    std::vector<Synapse>{ currentChildSynapse }));
            }
        }

        std::cout << "Adding neuron" << std::endl << std::endl;

        if (childrenOf.find(SimpleNeuron(i + 1, j + 1)) != childrenOf.end())
            currentLayer.AddNeuron(Neuron(parentOf, childrenOf.at(SimpleNeuron(i + 1, j + 1))));
        else
            currentLayer.AddNeuron(Neuron(parentOf, std::vector<Synapse>{}));
    }
    
    std::cout << "Adding layer" << std::endl << std::endl << std::endl;

    AddLayer(currentLayer);
}

Layer output;

std::cout << "Adding final layer" << std::endl;

for (int i = 0; i < neuronCountPerLayer[neuronCountPerLayer.size() - 1]; ++i)
    output.AddNeuron(Neuron(std::vector<Synapse>(), childrenOf.at(SimpleNeuron(neuronCountPerLayer.size(), i + 1))));
AddLayer(output);
}
float Neuron::FireSynapse()
{
float sum = 0.0f;

std::cout << "Firing Synapse!" << std::endl;

for (std::vector<Synapse>::iterator it = m_ChildOfSynapses.begin(); it != m_ChildOfSynapses.end(); ++it)
    sum += ((*it).GetWeightDiscriminate() * (*it).GetParent().GetValue());

std::cout << "Total sum: " << sum << std::endl;

float probability = (1 / (1 + pow(e, -sum)));

std::cout << "Probably of firing: " << probability << std::endl;

if (probability > 0.9f)
    return 1.0f;

else if (probability < 0.1f)
    return 0.0f;

else
{
    std::cout << "Using stochastic processing to determine firing" << std::endl;
    float random = ((rand() % 100) / 100);
    if (random <= probability)
        return 1.0f;
    else
        return 0.0f;
}
}
Added beautified code
Source Link
Loading
Source Link
Loading