统计各方面指标的java代码(3)

WonderfulFile.java

package wonderful.io;


import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;


import wonderful.tool.Constant;


public class WonderfulFile {


private static ArrayList<String> lineDataArr;


public static ArrayList<String> readFile3D(String fileName) {
if (fileName.equals("")) {
return readFile(Constant.WORKSPACE + "\\ZCoutput3d.txt");
} else {
return readFile(fileName);
}
}


public static ArrayList<String> readFileSport(String fileName) {
if (fileName.equals("")) {
return readFile(Constant.WORKSPACE + "\\dlt.txt");
} else {
return readFile(fileName);
}
}


/**
* lineDataArrを取得します.

* @return lineDataArr
*/
public static ArrayList<String> getLineDataArr() {
return lineDataArr;
}


public static ArrayList<String> readFile(String fileName) {


if (fileName.equals("")) {
fileName = Constant.WORKSPACE + "\\wonderful.txt";
}


lineDataArr = new ArrayList<String>();


FileInputStream fileInputStream;


try {
fileInputStream = new FileInputStream(fileName);


try {


BufferedReader is = new BufferedReader(


new InputStreamReader(fileInputStream));


String inputLine;


while ((inputLine = is.readLine()) != null) {
lineDataArr.add(inputLine);
}


is.close();


} catch (IOException e) {
e.printStackTrace();
}


fileInputStream.close();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
} catch (IOException e) {


e.printStackTrace();
}


return lineDataArr;
}





}


AppearMain.java

package wonderful.main;


import java.util.ArrayList;


public class AppearMain {




public static ArrayList<ArrayList<Integer>> GenerateLoteDyna8(int loteCnt,
ArrayList<Integer> numRedAll) {


ArrayList<ArrayList<Integer>> lotes = new ArrayList<ArrayList<Integer>>(
20000000);


for (int i1 = 0; i1 < numRedAll.size() - loteCnt + 1; i1++) {
ArrayList<Integer> lote = new ArrayList<Integer>();
if (lote.size() < 1) {
lote.add(numRedAll.get(i1));
} else {
lote.set(0, numRedAll.get(i1));
}
for (int i2 = i1 + 1; i2 < numRedAll.size() - loteCnt + 2; i2++) {
if (lote.size() < 2) {
lote.add(numRedAll.get(i2));
} else {
lote.set(1, numRedAll.get(i2));
}
for (int i3 = i2 + 1; i3 < numRedAll.size() - loteCnt + 3; i3++) {
if (lote.size() < 3) {
lote.add(numRedAll.get(i3));
} else {
lote.set(2, numRedAll.get(i3));
}
for (int i4 = i3 + 1; i4 < numRedAll.size() - loteCnt + 4; i4++) {
if (lote.size() < 4) {
lote.add(numRedAll.get(i4));
} else {
lote.set(3, numRedAll.get(i4));
}
for (int i5 = i4 + 1; i5 < numRedAll.size() - loteCnt
+ 5; i5++) {
if (lote.size() < 5) {
lote.add(numRedAll.get(i5));
} else {
lote.set(4, numRedAll.get(i5));
}
for (int i6 = i5 + 1; i6 < numRedAll.size()
- loteCnt + 6; i6++) {
if (lote.size() < 6) {
lote.add(numRedAll.get(i6));
} else {
lote.set(5, numRedAll.get(i6));
}
for (int i7 = i6 + 1; i7 < numRedAll.size()
- loteCnt + 7; i7++) {
if (lote.size() < 7) {
lote.add(numRedAll.get(i7));
} else {
lote.set(6, numRedAll.get(i7));
}
for (int i8 = i7 + 1; i8 < numRedAll.size()
- loteCnt + 8; i8++) {
if (lote.size() < 8) {
lote.add(numRedAll.get(i8));
} else {
lote.set(7, numRedAll.get(i8));
}
ArrayList<Integer> newlote = (ArrayList<Integer>) lote
.clone();
lotes.add(newlote);
}
}
}
}
}
}
}


}


return lotes;
}


public static ArrayList<ArrayList<Integer>> GenerateLoteDyna7(int loteCnt,
ArrayList<Integer> numRedAll) {


ArrayList<ArrayList<Integer>> lotes = new ArrayList<ArrayList<Integer>>(
20000000);


for (int i1 = 0; i1 < numRedAll.size() - loteCnt + 1; i1++) {
ArrayList<Integer> lote = new ArrayList<Integer>();
if (lote.size() < 1) {
lote.add(numRedAll.get(i1));
} else {
lote.set(0, numRedAll.get(i1));
}
for (int i2 = i1 + 1; i2 < numRedAll.size() - loteCnt + 2; i2++) {
if (lote.size() < 2) {
lote.add(numRedAll.get(i2));
} else {
lote.set(1, numRedAll.get(i2));
}
for (int i3 = i2 + 1; i3 < numRedAll.size() - loteCnt + 3; i3++) {
if (lote.size() < 3) {
lote.add(numRedAll.get(i3));
} else {
lote.set(2, numRedAll.get(i3));
}
for (int i4 = i3 + 1; i4 < numRedAll.size() - loteCnt + 4; i4++) {
if (lote.size() < 4) {
lote.add(numRedAll.get(i4));
} else {
lote.set(3, numRedAll.get(i4));
}
for (int i5 = i4 + 1; i5 < numRedAll.size() - loteCnt
+ 5; i5++) {
if (lote.size() < 5) {
lote.add(numRedAll.get(i5));
} else {
lote.set(4, numRedAll.get(i5));
}
for (int i6 = i5 + 1; i6 < numRedAll.size()
- loteCnt + 6; i6++) {
if (lote.size() < 6) {
lote.add(numRedAll.get(i6));
} else {
lote.set(5, numRedAll.get(i6));
}
for (int i7 = i6 + 1; i7 < numRedAll.size()
- loteCnt + 7; i7++) {
if (lote.size() < 7) {
lote.add(numRedAll.get(i7));
} else {
lote.set(6, numRedAll.get(i7));
}
ArrayList<Integer> newlote = (ArrayList<Integer>) lote
.clone();
lotes.add(newlote);
}
}
}
}
}
}


}


return lotes;
}





public static ArrayList<ArrayList<Integer>> GenerateLoteDyna5(int loteCnt,
ArrayList<Integer> numRedAll) {


ArrayList<ArrayList<Integer>> lotes = new ArrayList<ArrayList<Integer>>(
20000000);


for (int i1 = 0; i1 < numRedAll.size() - loteCnt + 1; i1++) {
ArrayList<Integer> lote = new ArrayList<Integer>();
if (lote.size() < 1) {
lote.add(numRedAll.get(i1));
} else {
lote.set(0, numRedAll.get(i1));
}
for (int i2 = i1 + 1; i2 < numRedAll.size() - loteCnt + 2; i2++) {
if (lote.size() < 2) {
lote.add(numRedAll.get(i2));
} else {
lote.set(1, numRedAll.get(i2));
}
for (int i3 = i2 + 1; i3 < numRedAll.size() - loteCnt + 3; i3++) {
if (lote.size() < 3) {
lote.add(numRedAll.get(i3));
} else {
lote.set(2, numRedAll.get(i3));
}
for (int i4 = i3 + 1; i4 < numRedAll.size() - loteCnt + 4; i4++) {
if (lote.size() < 4) {
lote.add(numRedAll.get(i4));
} else {
lote.set(3, numRedAll.get(i4));
}
for (int i5 = i4 + 1; i5 < numRedAll.size() - loteCnt
+ 5; i5++) {
if (lote.size() < 5) {
lote.add(numRedAll.get(i5));
} else {
lote.set(4, numRedAll.get(i5));
}


ArrayList<Integer> newlote = (ArrayList<Integer>) lote
.clone();
lotes.add(newlote);


}
}
}
}


}


return lotes;
}


public static ArrayList<ArrayList<Integer>> GenerateLoteDyna4(int loteCnt,
ArrayList<Integer> numRedAll) {


ArrayList<ArrayList<Integer>> lotes = new ArrayList<ArrayList<Integer>>(
330);


for (int i1 = 0; i1 < numRedAll.size() - loteCnt + 1; i1++) {
ArrayList<Integer> lote = new ArrayList<Integer>();
if (lote.size() < 1) {
lote.add(numRedAll.get(i1));
} else {
lote.set(0, numRedAll.get(i1));
}
for (int i2 = i1 + 1; i2 < numRedAll.size() - loteCnt + 2; i2++) {
if (lote.size() < 2) {
lote.add(numRedAll.get(i2));
} else {
lote.set(1, numRedAll.get(i2));
}
for (int i3 = i2 + 1; i3 < numRedAll.size() - loteCnt + 3; i3++) {
if (lote.size() < 3) {
lote.add(numRedAll.get(i3));
} else {
lote.set(2, numRedAll.get(i3));
}
for (int i4 = i3 + 1; i4 < numRedAll.size() - loteCnt + 4; i4++) {
if (lote.size() < 4) {
lote.add(numRedAll.get(i4));
} else {
lote.set(3, numRedAll.get(i4));
}
ArrayList<Integer> newlote = (ArrayList<Integer>) lote
.clone();
lotes.add(newlote);
}
}
}


}


return lotes;
}





public static ArrayList<ArrayList<Integer>> GenerateLoteDyna6(int loteCnt,
ArrayList<Integer> numRedAll) {


ArrayList<ArrayList<Integer>> lotes = new ArrayList<ArrayList<Integer>>(
20000000);


for (int i1 = 0; i1 < numRedAll.size() - loteCnt + 1; i1++) {
ArrayList<Integer> lote = new ArrayList<Integer>();
if (lote.size() < 1) {
lote.add(numRedAll.get(i1));
} else {
lote.set(0, numRedAll.get(i1));
}
for (int i2 = i1 + 1; i2 < numRedAll.size() - loteCnt + 2; i2++) {
if (lote.size() < 2) {
lote.add(numRedAll.get(i2));
} else {
lote.set(1, numRedAll.get(i2));
}
for (int i3 = i2 + 1; i3 < numRedAll.size() - loteCnt + 3; i3++) {
if (lote.size() < 3) {
lote.add(numRedAll.get(i3));
} else {
lote.set(2, numRedAll.get(i3));
}
for (int i4 = i3 + 1; i4 < numRedAll.size() - loteCnt + 4; i4++) {
if (lote.size() < 4) {
lote.add(numRedAll.get(i4));
} else {
lote.set(3, numRedAll.get(i4));
}
for (int i5 = i4 + 1; i5 < numRedAll.size() - loteCnt
+ 5; i5++) {
if (lote.size() < 5) {
lote.add(numRedAll.get(i5));
} else {
lote.set(4, numRedAll.get(i5));
}


for (int i6 = i5 + 1; i6 < numRedAll.size()
- loteCnt + 6; i6++) {
if (lote.size() < 6) {
lote.add(numRedAll.get(i6));
} else {
lote.set(5, numRedAll.get(i6));
}


ArrayList<Integer> newlote = (ArrayList<Integer>) lote
.clone();
lotes.add(newlote);
}


}
}
}
}


}


return lotes;
}



}

2018-02-05 2018036 3 6 5 48,547,166
2018-02-04 2018035 8 5 6 48,547,166
2018-02-03 2018034 6 7 6 48,547,166

Loted.java

package wonderful.analyzer;


import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;


public class Loted {


// 6|0 6|0 6|0 X


// 7498 1716


private static ArrayList<ArrayList<Integer>> arrsRed = new ArrayList<ArrayList<Integer>>();


private static ArrayList<ArrayList<Integer>> arrsTestRed = new ArrayList<ArrayList<Integer>>();


public static void setArrsTestRed(ArrayList<ArrayList<Integer>> arrsTestRed) {
Loted.arrsTestRed = arrsTestRed;
}


private static ArrayList<ArrayList<Integer>> arrsBlue = new ArrayList<ArrayList<Integer>>();


private static ArrayList<ArrayList<Integer>> arrsTerm = new ArrayList<ArrayList<Integer>>();


private static ArrayList<ArrayList<Integer>> arrsTermAll = new ArrayList<ArrayList<Integer>>();


public static int[][] arrsRedS;


public static int[][] arrsBlueS;


public static int[][] arrsTermS;


public static int[][] arrsTermAllS;


private static LinkedHashMap<Integer, Integer> mapSum = new LinkedHashMap<Integer, Integer>();


private static LinkedHashMap<ArrayList<Integer>, Integer> mapComposite = new LinkedHashMap<ArrayList<Integer>, Integer>();


private static LinkedHashMap<ArrayList<Integer>, Integer> continuousCompositeMap = new LinkedHashMap<ArrayList<Integer>, Integer>();


private static LinkedHashMap<ArrayList<Integer>, Integer> minMaxMap = new LinkedHashMap<ArrayList<Integer>, Integer>();


private static LinkedHashMap<ArrayList<Integer>, ArrayList<Integer>> NoAppearTimesMap = new LinkedHashMap<ArrayList<Integer>, ArrayList<Integer>>();


private static LinkedHashMap<LinkedHashMap<Integer, Integer>, LinkedHashMap<Integer, Integer>> NoAppearTimesMapAll = new LinkedHashMap<LinkedHashMap<Integer, Integer>, LinkedHashMap<Integer, Integer>>();


// {0=6|0, 1=5|1, 2=4|1, 3=2|1, 4=5|1, 5=2|1, 6=1|0, 7=2|0, 10=2|1, 12=1|0,
// 13=1|0, 15=1|0,
// 17=1|0}
private static ArrayList<LinkedHashMap<Integer, String>> distributionMapArr = new ArrayList<LinkedHashMap<Integer, String>>();


private static ArrayList<ArrayList<ArrayList<Integer>>> compositePrepareArr = new ArrayList<ArrayList<ArrayList<Integer>>>();


private static ArrayList<ArrayList<ArrayList<Integer>>> compositeSixArr = new ArrayList<ArrayList<ArrayList<Integer>>>();


public static void reset() {
arrsRed = new ArrayList<ArrayList<Integer>>();


arrsTermAll = new ArrayList<ArrayList<Integer>>();


arrsBlue = new ArrayList<ArrayList<Integer>>();


mapSum = new LinkedHashMap<Integer, Integer>();


mapComposite = new LinkedHashMap<ArrayList<Integer>, Integer>();


continuousCompositeMap = new LinkedHashMap<ArrayList<Integer>, Integer>();


minMaxMap = new LinkedHashMap<ArrayList<Integer>, Integer>();


NoAppearTimesMap = new LinkedHashMap<ArrayList<Integer>, ArrayList<Integer>>();


NoAppearTimesMapAll = new LinkedHashMap<LinkedHashMap<Integer, Integer>, LinkedHashMap<Integer, Integer>>();


// {0=6|0, 1=5|1, 2=4|1, 3=2|1, 4=5|1, 5=2|1, 6=1|0, 7=2|0, 10=2|1,
// 12=1|0, 13=1|0, 15=1|0,
// 17=1|0}
distributionMapArr = new ArrayList<LinkedHashMap<Integer, String>>();


compositePrepareArr = new ArrayList<ArrayList<ArrayList<Integer>>>();


compositeSixArr = new ArrayList<ArrayList<ArrayList<Integer>>>();
}


public static void getLotedData(ArrayList<String> WonderfulLineDataArr) {


for (String lineData : WonderfulLineDataArr) {


getLineNumData(lineData);
}


}


public static void getLotedDataSport(ArrayList<String> WonderfulLineDataArr) {


for (String lineData : WonderfulLineDataArr) {


getLineNumDataSports(lineData);
}


}


public static void getLotedData3D(ArrayList<String> WonderfulLineDataArr) {


for (String lineData : WonderfulLineDataArr) {


getLineNumData3D(lineData);
}


}


private static void getLineNumData3D(String lineData) {


ArrayList<Integer> arrRed = new ArrayList<Integer>(3);


ArrayList<Integer> arrTestRed = new ArrayList<Integer>(3);


ArrayList<Integer> arrTerm = new ArrayList<Integer>(1);


ArrayList<Integer> arrTermAll = new ArrayList<Integer>(1);


String arr[] = lineData.split(" ");


if (arr.length == 11) {


for (int i = 6; i < 9; i++) {
arrRed.add(Integer.parseInt(arr[i]));
}
arrsRed.add(arrRed);


for (int i = 2; i < 5; i++) {
arrTestRed.add(Integer.parseInt(arr[i]));
}
arrsTestRed.add(arrTestRed);


} else {
for (int i = 2; i < 5; i++) {
arrRed.add(Integer.parseInt(arr[i]));
}
arrsRed.add(arrRed);
}


if (arr[1].length() == 7) {
arrTerm.add(Integer.parseInt(arr[1].substring(4, 7)));
arrsTerm.add(arrTerm);
} else {
arrTerm.add(Integer.parseInt(arr[1].substring(2, 5)));
arrsTerm.add(arrTerm);
}


arrTermAll.add(Integer.parseInt(arr[1]));
arrsTermAll.add(arrTermAll);


}


private static void getLineNumData(String lineData) {


ArrayList<Integer> arrRed = new ArrayList<Integer>(7);


ArrayList<Integer> arrBlue = new ArrayList<Integer>(1);


ArrayList<Integer> arrTerm = new ArrayList<Integer>(1);


ArrayList<Integer> arrTermAll = new ArrayList<Integer>(1);


String arr[] = lineData.split(" ");


for (int i = 3; i < 9; i++) {
arrRed.add(Integer.parseInt(arr[i]));
}
arrsRed.add(arrRed);


arrTerm.add(Integer.parseInt(arr[1].substring(4, 7)));
arrsTerm.add(arrTerm);


arrTermAll.add(Integer.parseInt(arr[1]));
arrsTermAll.add(arrTermAll);


arrBlue.add(Integer.parseInt(arr[9]));
arrsBlue.add(arrBlue);


}


private static void getLineNumDataSports(String lineData) {


ArrayList<Integer> arrRed = new ArrayList<Integer>(7);


ArrayList<Integer> arrBlue = new ArrayList<Integer>(2);


// ArrayList<Integer> arrTerm = new ArrayList<Integer>(1);


ArrayList<Integer> arrTermAll = new ArrayList<Integer>(1);


String arr[] = lineData.split("\t");


for (int i = 2; i < 7; i++) {
try {
arrRed.add(Integer.parseInt(arr[i]));
} catch (Exception e) {
System.out.println(e.getMessage());
}


}
arrsRed.add(arrRed);


// arrTerm.add(Integer.parseInt(arr[1].substring(4, 7)));
// arrsTerm.add(arrTerm);


arrTermAll.add(Integer.parseInt(arr[0]));
arrsTermAll.add(arrTermAll);


arrBlue.add(Integer.parseInt(arr[7]));
arrBlue.add(Integer.parseInt(arr[8]));


arrsBlue.add(arrBlue);


}

/**
     * arrsRedを取得します.
     *
     * @return arrsRed
     */
    public static ArrayList<ArrayList<Integer>> getArrsRed() {
        return arrsRed;
    }


/**
* arrsTerm銈掑彇寰椼仐銇俱仚.

* @return arrsTerm
*/
public static ArrayList<ArrayList<Integer>> getArrsTerm() {
return arrsTerm;
}


/**
* arrsTerm銈掕ō瀹氥仐銇俱仚.

* @param arrsTerm
*/
public static void setArrsTerm(ArrayList<ArrayList<Integer>> arrsTerm) {
Loted.arrsTerm = arrsTerm;
}


/**
* arrsTermAll銈掑彇寰椼仐銇俱仚.

* @return arrsTermAll
*/
public static ArrayList<ArrayList<Integer>> getArrsTermAll() {
return arrsTermAll;
}


/**
* arrsTermAll銈掕ō瀹氥仐銇俱仚.

* @param arrsTermAll
*/
public static void setArrsTermAll(ArrayList<ArrayList<Integer>> arrsTermAll) {
Loted.arrsTermAll = arrsTermAll;
}


/**
* arrsTestRed銈掑彇寰椼仐銇俱仚.

* @return arrsTestRed
*/
public static ArrayList<ArrayList<Integer>> getArrsTestRed() {
return arrsTestRed;
}


/**
* arrsTestRed銈掕ō瀹氥仐銇俱仚.

* @param arrsTestRed
*/


}


Utils.java

package ai;


public class Utils {


// returns a random integer between x and y
public static double RandFloat() {
return Math.random();
}


// returns a random float in the range -1 < n < 1
public static double RandomClamped() {
return RandFloat() - RandFloat();
}


//x+1 ~ y
public static int RandInt(int x, int y) {
return (int) (Math.random() * (y - x)) + x+1;
}


public static boolean RandBool() {
if (RandInt(0, 1) == 1) {
return true;
} else {
return false;
}
}

}


CNeuralNet.java

package ai;


import java.util.ArrayList;
import java.util.Vector;


public class CNeuralNet {


int m_NumInputs;


int m_NumOutputs;


int m_NumHiddenLayers;


int m_NeuronsPerHiddenLyr;


// storage for each layer of neurons including the output layer
Vector<SNeuronLayer> m_vecLayers;


// ------------------------------default ctor ----------------------------
//
// creates a ANN based on the default values in params.ini
public CNeuralNet() {
// -----------------------------------------------------------------------
m_NumInputs = CParams.iNumInputs;
m_NumOutputs = CParams.iNumOutputs;
m_NumHiddenLayers = CParams.iNumHidden;
m_NeuronsPerHiddenLyr = CParams.iNeuronsPerHiddenLayer;


CreateNet();


}


// ------------------------------createNet()------------------------------
//
// this method builds the ANN. The weights are all initially set to
// random values -1 < w < 1
// ------------------------------------------------------------------------
public void CreateNet() {

m_vecLayers = new Vector<SNeuronLayer>();
// create the layers of the network
if (m_NumHiddenLayers > 0) {
// create first hidden layer
m_vecLayers
.add(new SNeuronLayer(m_NeuronsPerHiddenLyr, m_NumInputs));


for (int i = 0; i < m_NumHiddenLayers - 1; ++i) {


m_vecLayers.add(new SNeuronLayer(m_NeuronsPerHiddenLyr,
m_NeuronsPerHiddenLyr));
}


// create output layer
m_vecLayers.add(new SNeuronLayer(m_NumOutputs,
m_NeuronsPerHiddenLyr));
}


else {
// create output layer
m_vecLayers.add(new SNeuronLayer(m_NumOutputs, m_NumInputs));
}
}


// ---------------------------------GetWeights-----------------------------
//
// returns a vector containing the weights
//
// ------------------------------------------------------------------------
public ArrayList<Double> GetWeights() {
// this will hold the weights
ArrayList<Double> weights = new ArrayList<Double>();


// for each layer
for (int i = 0; i < m_NumHiddenLayers + 1; ++i) {


// for each neuron
for (int j = 0; j < m_vecLayers.get(i).m_NumNeurons; ++j) {
// for each weight
for (int k = 0; k < m_vecLayers.get(i).m_vecNeurons.get(j).m_NumInputs; ++k) {
weights.add(m_vecLayers.get(i).m_vecNeurons.get(j).m_vecWeight
.get(k));
}
}
}


return weights;
}


// -----------------------------------PutWeights---------------------------
//
// given a vector of doubles this function replaces the weights in the NN
// with the new values
//
// ------------------------------------------------------------------------
public void PutWeights(ArrayList<Double> weights) {
int cWeight = 0;


// for each layer
for (int i = 0; i < m_NumHiddenLayers + 1; ++i) {


// for each neuron
for (int j = 0; j < m_vecLayers.get(i).m_NumNeurons; ++j) {
// for each weight
for (int k = 0; k < m_vecLayers.get(i).m_vecNeurons.get(j).m_NumInputs; ++k) {
m_vecLayers.get(i).m_vecNeurons.get(j).m_vecWeight.set(k,
weights.get(cWeight));
cWeight++;
}
}
}


}


// ---------------------------------GetNumberOfWeights---------------------
//
// returns the total number of weights needed for the net
//
// ------------------------------------------------------------------------
public int GetNumberOfWeights() {


int weights = 0;


// for each layer
for (int i = 0; i < m_NumHiddenLayers + 1; ++i) {


// for each neuron
for (int j = 0; j < m_vecLayers.get(i).m_NumNeurons; ++j) {
// for each weight
for (int k = 0; k < m_vecLayers.get(i).m_vecNeurons.get(j).m_NumInputs; ++k)
weights++;
}
}


return weights;
}


// -------------------------------Update-----------------------------------
//
// given an input vector this function calculates the output vector
//
// ------------------------------------------------------------------------
public ArrayList<Double> Update(ArrayList<Double> inputs) {
// stores the resultant outputs from each layer
ArrayList<Double> outputs = new ArrayList<Double>();


int cWeight = 0;


// first check that we have the correct amount of inputs
if (inputs.size() != m_NumInputs) {
// just return an empty vector if incorrect.
return outputs;
}


// For each layer....
for (int i = 0; i < m_NumHiddenLayers + 1; ++i) {


if (i > 0) {
inputs = outputs;
}


outputs = new ArrayList<Double>();


cWeight = 0;


// for each neuron sum the (inputs * corresponding weights).Throw
// the total at our sigmoid function to get the output.
for (int j = 0; j < m_vecLayers.get(i).m_NumNeurons; ++j) {
double netinput = 0;


int NumInputs = m_vecLayers.get(i).m_vecNeurons.get(j).m_NumInputs;


// for each weight
for (int k = 0; k < NumInputs - 1; ++k) {
// sum the weights x inputs
try {
netinput += m_vecLayers.get(i).m_vecNeurons.get(j).m_vecWeight
.get(k) * inputs.get(cWeight);
cWeight++;
} catch (Exception e) {
System.out.println(cWeight);
}

}


// add in the bias
netinput += m_vecLayers.get(i).m_vecNeurons.get(j).m_vecWeight
.get(NumInputs - 1) * CParams.dBias;


// we can store the outputs from each layer as we generate them.
// The combined activation is first filtered through the sigmoid
// function
outputs.add(Sigmoid(netinput, CParams.dActivationResponse));


cWeight = 0;
}
}


return outputs;
}


// -------------------------------Sigmoid function-------------------------
//
// ------------------------------------------------------------------------
private double Sigmoid(double netinput, double response) {
return (1 / (1 + Math.exp(-netinput / response)));
}


// --------------------------- CalculateSplitPoints -----------------------
//
// this method calculates all points in the vector of weights which
// represent the start and end points of individual neurons
// ------------------------------------------------------------------------
public Vector<Integer> CalculateSplitPoints() {
Vector<Integer> SplitPoints = new Vector<Integer>();


int WeightCounter = 0;


// for each layer
for (int i = 0; i < m_NumHiddenLayers + 1; ++i) {
// for each neuron
for (int j = 0; j < m_vecLayers.get(i).m_NumNeurons; ++j) {
// for each weight
for (int k = 0; k < m_vecLayers.get(i).m_vecNeurons.get(j).m_NumInputs; ++k) {
++WeightCounter;
}


SplitPoints.add(WeightCounter - 1);
}
}


return SplitPoints;
}

}


SNeuron.java

package ai;


import java.util.ArrayList;


public class SNeuron {


// the number of inputs into the neuron
int m_NumInputs;


// the weights for each input
ArrayList<Double> m_vecWeight;


// ctor
public SNeuron(int NumInputs) {
m_NumInputs = NumInputs+1;
m_vecWeight = new ArrayList<Double>();
for (int i = 0; i < NumInputs + 1; ++i) {
// set up the weights with an initial random value
m_vecWeight.add(Utils.RandomClamped());
}
}


}


SNeuronLayer.java

package ai;


import java.util.Vector;


//---------------------------------------------------------------------
//struct to hold a layer of neurons.
//---------------------------------------------------------------------
public class SNeuronLayer {


// the number of neurons in this layer
int m_NumNeurons;


// the layer of neurons
Vector<SNeuron> m_vecNeurons;


// ************************ methods for NeuronLayer **********************


// -----------------------------------------------------------------------
// ctor creates a layer of neurons of the required size by calling the
// SNeuron ctor the rqd number of times
// -----------------------------------------------------------------------
public SNeuronLayer(int NumNeurons, int NumInputsPerNeuron) {
m_NumNeurons = NumNeurons;
m_vecNeurons = new Vector<SNeuron>();
for (int i = 0; i < NumNeurons; ++i)


m_vecNeurons.add(new SNeuron(NumInputsPerNeuron));
}

}


CParams.java

package ai;


import java.io.IOException;
import java.util.Properties;


public class CParams {


public static Properties pps;
// ------------------------------------general parameters
static double dPi;
static double dHalfPi;
static double dTwoPi;


static int WindowWidth;
static int WindowHeight;


static int iFramesPerSecond;


// -------------------------------------used for the neural network
public static int iNumInputs;
public static int iNumHidden;
public static int iNeuronsPerHiddenLayer;
public static int iNumOutputs;


// for tweeking the sigmoid function
public static double dActivationResponse;
// bias value
static double dBias;


// --------------------------------------used to define the sweepers
static double dEnergyCostPerTick;


// limits how fast the sweepers can turn
static double dMaxTurnRate;


static double dMaxSpeed;


// for controlling the size
static int iSweeperMul;


// the amount of energy a sweeper may start its life with
static double dStartEnergy;


// --------------------------------------controller parameters
static int iNumSweepers;


static int iNumMines;


// number of time steps we allow for each generation to live
static int iNumTicks;


// scaling factor for mines
static double dMineScale;


// ---------------------------------------GA parameters
static double dCrossoverRate;
static double dMutationRate;


// the maximum amount the ga may mutate each weight by
static double dMaxPerturbation;

static double dOtherPopPercent;


// used for elitism
static int iNumElite;
static int iNumCopiesElite;


public CParams() {
pps = new Properties();
try {
pps.load(CParams.class.getClassLoader().getResourceAsStream(
"params.ini"));


iNumInputs = Integer
.parseInt(CParams.pps.getProperty("iNumInputs"));
iNumOutputs = Integer.parseInt(CParams.pps
.getProperty("iNumOutputs"));
iNumHidden = Integer
.parseInt(CParams.pps.getProperty("iNumHidden"));
iNeuronsPerHiddenLayer = Integer.parseInt(CParams.pps
.getProperty("iNeuronsPerHiddenLayer"));
dBias = Double.parseDouble(CParams.pps.getProperty("dBias"));
dStartEnergy = Double.parseDouble(CParams.pps
.getProperty("dStartEnergy"));
iNumSweepers = Integer.parseInt(CParams.pps
.getProperty("iNumSweepers"));
dCrossoverRate = Double.parseDouble(CParams.pps
.getProperty("dCrossoverRate"));
dMutationRate = Double.parseDouble(CParams.pps
.getProperty("dMutationRate"));
iNumElite = Integer.parseInt(CParams.pps.getProperty("iNumElite"));
iNumCopiesElite = Integer.parseInt(CParams.pps
.getProperty("iNumCopiesElite"));
dActivationResponse = Double.parseDouble(CParams.pps
.getProperty("dActivationResponse"));
dOtherPopPercent = Double.parseDouble(CParams.pps
.getProperty("dOtherPopPercent"));
iSweeperMul = Integer
.parseInt(CParams.pps.getProperty("iSweeperMul"));


} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值