📄 dbtest.java
字号:
/* * NetworkController.java 1.0 30/10/2004 * * NeuralNetworkToolkit * Copyright (C) 2004 Universidade de Brasília * * This file is part of NeuralNetworkToolkit. * * NeuralNetworkToolkit is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * NeuralNetworkToolkit is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with NeuralNetworkToolkit; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA - 02111-1307 - USA. */ package neuralnetworktoolkit.tests;import neuralnetworktoolkit.NetworkController;import neuralnetworktoolkit.NetworkControllerException;import neuralnetworktoolkit.NeuralModel;import neuralnetworktoolkit.StatisticalResults;import neuralnetworktoolkit.datamanager.databasemanager.DbaseManager;import neuralnetworktoolkit.datamanager.textfilemanager.LoadFromFileManager;import neuralnetworktoolkit.math.NeuralMath;import neuralnetworktoolkit.methods.gradientbased.quasinewton.lm.*;import neuralnetworktoolkit.validation.ValidationStatistics;/** * @author iver * * TODO To change the template for this generated type comment go to * Window - Preferences - Java - Code Generation - Code and Comments */public class DBTest { public static void main(String[] args) { LoadFromFileManager lf = new LoadFromFileManager(); DbaseManager db = new DbaseManager("postgresql"); //db.setDriverName("org.postgresql.Driver"); db.connectDatabase("jdbc:postgresql://localhost/Iver","iver","x"); //db.setDriverName("com.mysql.jdbc.Driver"); //db.connectDatabase("jdbc:mysql://localhost/teste"); String[] tables = db.getTableNames(); String[] columns = null; System.out.println("Tabelas Existentes:"); for (int i = 0; i < tables.length; i++) { System.out.println("Nome da Tabela: " + tables[i]); columns = db.getTableColumnNames(tables[i]); for (int j = 0; j < columns.length; j++) { System.out.println("Nome da Coluna: " + columns[j]); } System.out.println(); } String[] trC = {"a","b"}; double[][] data = db.loadData("teste", trC); NeuralMath.printMatrix(data); StatisticalResults statistics; ValidationStatistics validationStatistics; System.out.println("Teste iniciado!"); NetworkController nc = new NetworkController(); try { int[] parameters = {1, 10, 1}; String[] functions = {"Tanh", "Tanh"}; String initialization = "NguyenWidrow"; nc.createNeuralNetwork(parameters, initialization, functions); nc.setNormalization("Linear", NetworkController.FULLNORMALIZER); int[] index = {1}; nc.setOutputIndex(index); nc.setTrainingData(data); nc.splitDataValues(); nc.setTrainingMethod("gradientbased.quasinewton.lm.OLMAM"); LevenbergMarquardtParameters trainParam = new LevenbergMarquardtParameters(); trainParam.setError(.000000000000000000000000005); trainParam.setLmKind(LevenbergMarquardtModel.INCOMPLETE_LM); trainParam.setMaxIterations(10); statistics = nc.trainNeuralNetwork(trainParam); System.out.println("Número de épocas: " + statistics.getNumberOfEpochs()); System.out.println("Número de iterações: " + statistics.getNumberIterations()); System.out.println("Erro do treinamento: " + statistics.getError()); System.out.println("Tempo de treinamento: " + statistics.getTrainingTime()); String[] inC = {"c"}; double[][] tdata = db.loadData("teste", inC); System.out.println("-----> Inferencia <-----"); nc.setInferenceData(tdata); nc.infereWithNetwork(); System.out.println("-----> Inferencia <-----"); db.saveNeuralModel("blo","hugo", nc.getNeuralModel()); } catch (NetworkControllerException e) { e.printStackTrace(); } System.out.println("Teste finalizado!"); String[][] existentModels; existentModels = db.getExistitentModels("blo", "hugo",.0005,null); if (existentModels != null) { System.out.println("Modelos existentes:"); for (int i = 0; i < existentModels.length; i++) { for (int j = 0; j < existentModels[0].length; j++) { System.out.print(existentModels[i][j] + " "); } System.out.println(); } } String[] chave = {"hugo","2004-11-14", "02:04:45"}; NetworkController retrievedNN = new NetworkController(); try { NeuralModel nm = db.retrieveModel("blo", chave); if (nm != null ) { System.out.println("Recuperei nao é nulo"); retrievedNN.createNeuralNetwork(nm); String[] inC = {"c"}; double[][] tdata = db.loadData("teste", inC); retrievedNN.setInferenceData(tdata); System.out.println("-----> Inferencia <-----"); retrievedNN.infereWithNetwork(); System.out.println("-----> Inferencia <-----"); } } catch (NetworkControllerException e1) { e1.printStackTrace(); } db.disconnectDatabase(); } // main() }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -