Pointer problem in neural network

[b][red]This message was edited by IDK at 2005-4-30 12:45:33[/red][/b][hr]
I've got some problem with pointers.
I want to build a neural network and
the input of each neuron should be
connected to the output from some
other neuron. The connection is
called a dendrite.

The problem is that C# doesn't like
pointers.
Is there any other way of doing this?

The error is in line 28, column 42, form.cs


Here's my code so far:
NeuralNetwork.cs
[code]
#region Using directives

using System;
using System.Collections.Generic;
using System.Text;

#endregion

namespace NeuralNetwork
{
public unsafe class NeuralNetwork
{
Neuron[] neurons = new Neuron[0];

public NeuralNetwork()
{
}
public Neuron this[int index] // Indexer declaration
{
get
{
return neurons[index];
}
set
{
neurons[index] = value;
}
}
public void addneuron(Neuron neuron)
{
Neuron[] temp = neurons;
neurons = new Neuron[temp.Length + 1];
for (int i = 0; i < temp.Length; i++)
{
neurons[i] = temp[i];
}
neurons[temp.Length] = neuron;
}
public void insertneuron(Neuron neuron, int pos)
{
Neuron[] temp = neurons;
neurons = new Neuron[temp.Length + 1];
int i = 0;
for (; i < pos; i++)
{
neurons[i] = temp[i];
}
neurons[i] = neuron;
for (; i < neurons.Length; i++)
{
neurons[i + 1] = temp[i];
}
}
}
public unsafe class Neuron
{
bool delay = false;
int bias = 1;
int*[] dendrites;
public int output = 0;

public Neuron(int Bias)
{
bias = Bias;
}
public Neuron(int Bias, bool Delay)
{
bias = Bias;
delay = Delay;
}
public Neuron(int*[] dendrite, int Bias, bool Delay)
{
dendrites = dendrite;
bias = Bias;
delay = Delay;
}
public Neuron(int* dendrite, int Bias, bool Delay)
{
adddendrite(dendrite);
bias = Bias;
delay = Delay;
}
public void adddendrite(int* dendrite)
{
int*[] temp = dendrites;
dendrites = new int*[temp.Length + 1];
for (int i = 0; i < dendrites.Length; i++)
{
dendrites[i] = temp[i];
}
dendrites[dendrites.Length] = dendrite;
}
public void insertdendrite(int* dendrite, int pos)
{
int*[] temp = dendrites;
dendrites = new int*[temp.Length + 1];
int i = 0;
for (; i < pos; i++)
{
dendrites[i] = temp[i];
}
dendrites[i] = dendrite;
for (; i < dendrites.Length; i++)
{
dendrites[i + 1] = temp[i];
}
}
public void Sumfunc()
{
int sum = bias;
for (int i = 0; i < dendrites.Length; i++)
{
sum += *dendrites[i];
}
output = sum;
}
public int* this[int index] // Indexer declaration
{
get
{
return dendrites[index];
}
set
{
dendrites[index] = value;
}
}
}
}

[/code]
Form1.cs
[code]#region Using directives

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;

#endregion

namespace NeuralNetwork
{
unsafe partial class Form1 : Form
{
NeuralNetwork nn;
public Form1()
{
InitializeComponent();
nn = new NeuralNetwork();
nn.addneuron(new Neuron(0, true));
nn.addneuron(new Neuron(0, true));
nn.addneuron(new Neuron(0, true));
nn.addneuron(new Neuron(0, true));
for (int i = 0; i < 4; i++)
for (int j = 0; j < 4; j++)
if (j != i)
nn[i].adddendrite(&nn[j].output); [red]//ERROR[/red]
}
}
}
[/code]
===============================
El [b]PRO[/b]grammador Niklas Ulvinge


Comments

  • [b][red]This message was edited by IDK at 2005-5-11 6:56:50[/red][/b][hr]
    Cmon.
    Noone have replied on any
    of my hard questions.

    I solved it anyway.
    It was rather easy but I'm
    not used to pointers.
    ===============================
    El [b]PRO[/b]grammador Niklas Ulvinge



Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion