// set network type
this.setNetworkType(NeuralNetworkType.NEURO_FUZZY_REASONER);
// createLayer input layer
NeuronProperties neuronProperties = new NeuronProperties();
Layer inLayer = LayerFactory.createLayer(new Integer(inputNum),
neuronProperties);
this.addLayer(inLayer);
// createLayer fuzzy set layer
neuronProperties.setProperty("transferFunction",
TransferFunctionType.TRAPEZOID);
Enumeration<Integer> e = inputSets.elements();
int fuzzySetsNum = 0;
while (e.hasMoreElements()) {
Integer i = e.nextElement();
fuzzySetsNum = fuzzySetsNum + i.intValue();
}
Layer setLayer = LayerFactory.createLayer(fuzzySetsNum,
neuronProperties);
this.addLayer(setLayer);
// TODO: postavi parametre funkcija pripadnosti
// nizove sa trning elementima iznesi van klase i prosledjuj ih kao
// parametre
Iterator<Neuron> ii = setLayer.getNeuronsIterator();
Enumeration<Integer> en;// =setLayer.neurons();
int c = 0;
while (ii.hasNext()) {
Neuron cell = ii.next();
Trapezoid tf = (Trapezoid) cell.getTransferFunction();
if (c <= 3) {
tf.setLeftLow(pointsSets[c][0]);
tf.setLeftHigh(pointsSets[c][1]);
tf.setRightLow(pointsSets[c][3]);
tf.setRightHigh(pointsSets[c][2]);
} else {
tf.setLeftLow(timeSets[c - 4][0]);
tf.setLeftHigh(timeSets[c - 4][1]);
tf.setRightLow(timeSets[c - 4][3]);
tf.setRightHigh(timeSets[c - 4][2]);
}
c++;
}
// povezi prvi i drugi sloj
int s = 0; // brojac celija sloja skupova (fazifikacije)
for (int i = 0; i < inputNum; i++) { // brojac ulaznih celija
Neuron from = inLayer.getNeuronAt(i);
int jmax = inputSets.elementAt(i).intValue();
for (int j = 0; j < jmax; j++) {
Neuron to = setLayer.getNeuronAt(s);
ConnectionFactory.createConnection(from, to, 1);
s++;
}
}
// ----------------------------------------------------------
// createLayer rules layer
NeuronProperties ruleNeuronProperties = new NeuronProperties(
WeightsFunctionType.WEIGHTED_INPUT,
SummingFunctionType.MIN,
TransferFunctionType.LINEAR);
en = inputSets.elements();
int fuzzyAntNum = 1;
while (en.hasMoreElements()) {
Integer i = en.nextElement();
fuzzyAntNum = fuzzyAntNum * i.intValue();
}
Layer ruleLayer = LayerFactory.createLayer(fuzzyAntNum,
ruleNeuronProperties);
this.addLayer(ruleLayer);
int scIdx = 0; // set cell index
for (int i = 0; i < inputNum; i++) { // brojac ulaza (grupa fuzzy
// skupova)
int setsNum = inputSets.elementAt(i).intValue();
for (int si = 0; si < setsNum; si++) { // brojac celija fuzzy
// skupova
if (i == 0) {
Neuron from = setLayer.getNeuronAt(si);
int connPerCell = fuzzyAntNum / setsNum;
scIdx = si;
for (int k = 0; k < connPerCell; k++) { // brojac celija
// hipoteza
Neuron to = ruleLayer.getNeuronAt(si * connPerCell + k);
ConnectionFactory.createConnection(from, to,
new Double(1));
} // for
} // if
else {
scIdx++;
Neuron from = setLayer.getNeuronAt(scIdx);
int connPerCell = fuzzyAntNum / setsNum;
for (int k = 0; k < connPerCell; k++) { // brojac celija
// hipoteza
int toIdx = si + k * setsNum;
Neuron to = ruleLayer.getNeuronAt(toIdx);
ConnectionFactory.createConnection(from, to,
new Double(1));
} // for k
} // else
} // for si
} // for i
// kreiraj izlazni sloj
neuronProperties = new NeuronProperties();
neuronProperties.setProperty("transferFunction",
TransferFunctionType.STEP);
Layer outLayer = LayerFactory.createLayer(new Integer(outNum),
neuronProperties);
this.addLayer(outLayer);
ConnectionFactory.fullConnect(ruleLayer, outLayer);