This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class NeuralLayer | |
{ | |
public List<INeuron> Neurons; | |
public NeuralLayer() | |
{ | |
Neurons = new List<INeuron>(); | |
} | |
/// <summary> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public interface ISynapse | |
{ | |
double Weight { get; set; } | |
double PreviousWeight { get; set; } | |
double GetOutput(); | |
bool IsFromNeuron(Guid fromNeuronId); | |
void UpdateWeight(double learningRate, double delta); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Synapse : ISynapse | |
{ | |
internal INeuron _fromNeuron; | |
internal INeuron _toNeuron; | |
/// <summary> | |
/// Weight of the connection. | |
/// </summary> | |
public double Weight { get; set; } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class InputSynapse : ISynapse | |
{ | |
internal INeuron _toNeuron; | |
public double Weight { get; set; } | |
public double Output { get; set; } | |
public double PreviousWeight { get; set; } | |
public InputSynapse(INeuron toNeuron) | |
{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SimpleNeuralNetwork | |
{ | |
private NeuralLayerFactory _layerFactory; | |
internal List<NeuralLayer> _layers; | |
internal double _learningRate; | |
internal double[][] _expectedResult; | |
/// <summary> | |
/// Constructor of the Neural Network. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var network = new SimpleNeuralNetwork(3); | |
var layerFactory = new NeuralLayerFactory(); | |
network.AddLayer(layerFactory.CreateNeuralLayer(3, new RectifiedActivationFuncion(), new WeightedSumFunction())); | |
network.AddLayer(layerFactory.CreateNeuralLayer(1, new SigmoidActivationFunction(0.7), new WeightedSumFunction())); | |
network.PushExpectedValues( | |
new double[][] { | |
new double[] { 0 }, | |
new double[] { 1 }, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
const1 = tf.constant([[1,2,3], [1,2,3]]); | |
const2 = tf.constant([[3,4,5], [3,4,5]]); | |
result = tf.add(const1, const2); | |
with tf.Session() as sess: | |
output = sess.run(result) | |
print(output) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import tensorflow as tf | |
var1 = tf.Variable([[1, 2], [1, 2]], name="variable1") | |
var2 = tf.Variable([[3, 4], [3, 4]], name="variable2") | |
result = tf.matmul(var1, var2) | |
with tf.Session() as sess: | |
output = sess.run(result) | |
print(output) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Import `tensorflow` and `pandas` | |
import tensorflow as tf | |
import pandas as pd | |
COLUMN_NAMES = [ | |
'SepalLength', | |
'SepalWidth', | |
'PetalLength', | |
'PetalWidth', | |
'Species' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Setup feature columns | |
columns_feat = [ | |
tf.feature_column.numeric_column(key='SepalLength'), | |
tf.feature_column.numeric_column(key='SepalWidth'), | |
tf.feature_column.numeric_column(key='PetalLength'), | |
tf.feature_column.numeric_column(key='PetalWidth') | |
] |