⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rbf.java

📁 RBF java file, complete
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
			} else
				nomFicheroCFG = nomFich;

			cout = new DataOutputStream(new FileOutputStream(nomFicheroCFG));
			// log("(-)(-)(-) SAVECFG: " + nomFicheroCFG + " (-)(-)(-)");

			// CABECERA
			cout.writeBytes("# Fichero de configuracion: annRBF: Artificial Neural Network: Radial Basis Function. Ver.: 1.0" + endl);
			cout.writeBytes("# Fichero base: " + nomFichero + " [" + numNeuronasEntrada + "x" + numNeuronasCentro + "x" + numNeuronasSalida + "]" + endl);
			cout.writeBytes(endl);

			// NEURONAS DE ENTRADA
			cout.writeBytes("# Numero de Neuronas de entrada" + endl);
			for (x = 0, linActual = "#"; x < numNeuronasEntrada; x++)
				linActual += " " + nomAtrib[x] + ",";
			linActual = linActual.substring(0, linActual.lastIndexOf(",")) + endl;
			cout.writeBytes("numNeuronasEntrada=" + numNeuronasEntrada + endl);
			cout.writeBytes(linActual);
			cout.writeBytes(endl);

			// NEURONAS DE SALIDA
			cout.writeBytes("# Numero de Neuronas de salida" + endl);
			for (x = 0, linActual = "#"; x < numNeuronasSalida; x++)
				linActual += " " + nomAtrib[numNeuronasEntrada + x] + ",";
			linActual = linActual.substring(0, linActual.lastIndexOf(",")) + endl;
			cout.writeBytes("numNeuronasSalida=" + numNeuronasSalida + endl);
			cout.writeBytes(linActual);
			cout.writeBytes(endl);

			// CENTROS
			cout.writeBytes("# Numero de Centros" + endl);
			cout.writeBytes("# sigma, val1, val2, ... ,valn" + endl);
			cout.writeBytes("numNeuronasCentro=" + numNeuronasCentro + endl);
			for (x = 0; x < numNeuronasCentro; x++) {
				linActual = "" + neuronasCentro[x].sigma + ",\t";
				for (y = 0; y < numNeuronasEntrada; y++)
					linActual += neuronasCentro[x].vectorValores[y] + ",\t";
				linActual = linActual.substring(0, linActual.lastIndexOf(",")) + endl;
				cout.writeBytes(linActual);
			}
			cout.writeBytes(endl);

			// CONECTORES CENTRO <-> SALIDA
			cout.writeBytes("# Numero de Conectores Centro <-> Salida" + endl);
			cout.writeBytes("numConectoresCentro=" + (numNeuronasCentro * numNeuronasSalida) + endl);
			for (x = 0; x < numNeuronasCentro; x++) {
				for (y = 0, linActual = ""; y < numNeuronasSalida; y++)
					linActual += conectorCS[x][y].pesoActual + ",\t";
				linActual = linActual.substring(0, linActual.lastIndexOf(",")) + endl;
				cout.writeBytes(linActual);
			}
			cout.writeBytes(endl);

			// CONECTORES BIAS <-> SALIDA
			cout.writeBytes("# Numero de Conectores Bias <-> Salida" + endl);
			cout.writeBytes("numConectoresBias=" + numNeuronasSalida + endl);
			for (y = 0, linActual = ""; y < numNeuronasSalida; y++)
				linActual += conectorBS[y].pesoActual + ",\t";
			linActual = linActual.substring(0, linActual.lastIndexOf(",")) + endl;
			cout.writeBytes(linActual);
			cout.writeBytes(endl);

			cout.writeBytes("# Fin del fichero de configuracion");
			cout.flush();
			cout.close();
		} catch (IOException ex) {
			ex.printStackTrace();
			ex.printStackTrace(new PrintWriter(fichLog));
		}
	}

	// LOADCFG
	protected void loadCFG_(String nomFich) {
		if (noHayDatos())
			return;

		int y, x;
		BufferedReader cin;
		StringTokenizer tokens;
		String linActual = "", valorAct, nomFicheroCFG;

		try {
			if (nomFich.length() == 0) {
				nomFicheroCFG = nomFichero.substring(0, nomFichero.lastIndexOf(".")) + "_RBF.cfg";
				System.out.println("");
				System.out.print("Introduce el nombre del fichero, [" + nomFicheroCFG + "]: ");
				valorAct = teclado.readLine();
				nomFicheroCFG = (valorAct.length() == 0) ? nomFicheroCFG : valorAct;
			} else
				nomFicheroCFG = nomFich;

			cin = new BufferedReader(new InputStreamReader(new FileInputStream(nomFicheroCFG)));
			// log("(-)(-)(-) LOADCFG: " + nomFicheroCFG + " (-)(-)(-)");

			while ((linActual = cin.readLine()) != null) {
				if (linActual.trim().startsWith("#") | linActual.length() == 0)
					continue;

				if (linActual.trim().startsWith("numNeuronasEntrada")) {
					valorAct = linActual.substring(linActual.indexOf("=") + 1, linActual.length()).trim();
					numNeuronasEntrada = new Integer(valorAct).intValue();
				} else if (linActual.trim().startsWith("numNeuronasSalida")) {
					valorAct = linActual.substring(linActual.indexOf("=") + 1, linActual.length()).trim();
					numNeuronasSalida = new Integer(valorAct).intValue();
				} else if (linActual.trim().startsWith("numNeuronasCentro")) {
					valorAct = linActual.substring(linActual.indexOf("=") + 1, linActual.length()).trim();
					numNeuronasCentro = new Integer(valorAct).intValue();

					generateNetwork(numNeuronasCentro);

					for (y = 0; y < numNeuronasCentro; y++) {
						linActual = cin.readLine();
						tokens = new StringTokenizer(linActual, SEPARADOR, false);
						neuronasCentro[y].sigma = new Float(tokens.nextToken()).floatValue();
						for (x = 0; x < numNeuronasEntrada; x++)
							neuronasCentro[y].vectorValores[x] = new Float(tokens.nextToken()).floatValue();
					}
				} else if (linActual.trim().startsWith("numConectoresCentro")) {
					for (y = 0; y < numNeuronasCentro; y++) {
						linActual = cin.readLine();
						tokens = new StringTokenizer(linActual, SEPARADOR, false);
						for (x = 0; x < numNeuronasSalida; x++)
							conectorCS[y][x].establecerPeso(new Float(tokens.nextToken()).floatValue());
					}
				} else if (linActual.trim().startsWith("numConectoresBias")) {
					linActual = cin.readLine();
					tokens = new StringTokenizer(linActual, SEPARADOR, false);
					for (y = 0; y < numNeuronasSalida; y++)
						conectorBS[y].establecerPeso(new Float(tokens.nextToken()).floatValue());
				} else {
					System.out.println(endl + "Error en el fichero de configuracion!");
					System.out.println(linActual);
					return;
				}
			}

		} catch (IOException ex) {
			ex.printStackTrace();
			ex.printStackTrace(new PrintWriter(fichLog));
		}
	}

	// LOADGCS
	protected void loadGCS_(String nomFich) {
		if (noHayDatos())
			return;

		int y, x;
		BufferedReader cin;
		StringTokenizer tokens;
		String linActual = "", valorAct, nomFicheroGCS;

		Nodos = new Vector();
		NodoGCS nRef = null;

		try {
			if (nomFich.length() == 0) {
				nomFicheroGCS = nomFichero.substring(0, nomFichero.lastIndexOf(".")) + "_GCS.cfg";
				System.out.println("");
				System.out.print("Introduce el nombre del fichero, [" + nomFicheroGCS + "]: ");
				valorAct = teclado.readLine();
				nomFicheroGCS = (valorAct.length() == 0) ? nomFicheroGCS : valorAct;
			} else
				nomFicheroGCS = nomFich;

			cin = new BufferedReader(new InputStreamReader(new FileInputStream(nomFicheroGCS)));
			// log("(-)(-)(-) LOADGCS: " + nomFicheroCFG + " (-)(-)(-)");

			while ((linActual = cin.readLine()) != null) {
				if (linActual.trim().startsWith("#") | linActual.length() == 0)
					continue;

				// Identificacion de un nuevo nodo
				if (linActual.trim().startsWith("Nodo=")) {
					valorAct = linActual.substring(linActual.indexOf("=") + 1, linActual.length()).trim();
					nRef = new NodoGCS();
					Nodos.addElement(nRef);
				}
				// Vector de posicion del nodo
				else if (linActual.trim().startsWith("w=")) {
					valorAct = linActual.substring(linActual.indexOf("=") + 1, linActual.length()).trim();
					nRef.setW(valorAct);
				}
				// Nodos vecinos del nuevo nodo
				else if (linActual.trim().startsWith("nodosVecinos=")) {
					valorAct = linActual.substring(linActual.indexOf("=") + 1, linActual.length()).trim();
					nRef.setNodosVecinos(valorAct);
				}
				// Distancia entre el nodo y cada uno de sus vecinos
				else if (linActual.trim().startsWith("distNodosVecinos=")) {
					valorAct = linActual.substring(linActual.indexOf("=") + 1, linActual.length()).trim();
					nRef.setDistNodosVecinos(valorAct);
				}
				// Casos agrupados por el nodo
				else if (linActual.trim().startsWith("casosAgrupados=")) {
					valorAct = linActual.substring(linActual.indexOf("=") + 1, linActual.length()).trim();
					nRef.setCasosAgrupados(valorAct);
				} else if (linActual.trim().startsWith("contVictorias=")) {
					valorAct = linActual.substring(linActual.indexOf("=") + 1, linActual.length()).trim();
					nRef.contVictorias = new Float(valorAct).floatValue();
				}
			}
		} catch (IOException ex) {
			ex.printStackTrace();
			ex.printStackTrace(new PrintWriter(fichLog));
		}

		// Llamamos al recolector de basura
		System.gc();
	}

	// INIC
	protected void inic_(Hashtable<String, Float> parameters) {
		if (noHayDatos())
			return;

		int opcion;

		log("(-)(-)(-) INIC: (-)(-)(-)");
		// System.out.println("");
		try {
			// NEURONAS DE ENTRADA
			try {
				/*
				 * System.out.print("Numero de neuronas de entrada, \t[" +
				 * (numAtributos-1) + "]: "); try { valorAct =
				 * teclado.readLine(); } catch (IOException e) { // TODO
				 * Auto-generated catch block e.printStackTrace(); }
				 */
				numNeuronasEntrada = parameters.get("inputNeuronNumber").intValue();
			} catch (NumberFormatException e) {
				numNeuronasEntrada = numAtributos - 1;
				neuronasEntrada = new NeuronaSimple[numNeuronasEntrada];
			} finally {
				log("\tNeuronas en la capa de entrada: " + numNeuronasEntrada);
			}

			// NEURONAS DE SALIDA
			try {
				// System.out.print("Numero de neuronas de salida, \t[" +
				// (numAtributos - numNeuronasEntrada) + "]: ");
				// valorAct = teclado.readLine();
				numNeuronasSalida = parameters.get("outputNeuronNumber").intValue();
			} catch (NumberFormatException e) {
				numNeuronasSalida = numAtributos - numNeuronasEntrada;
				neuronasSalida = new NeuronaSimple[numNeuronasSalida];
			} finally {
				log("\tNeuronas en la capa de salida: " + numNeuronasSalida);
			}

			// PESO MINIMO DE LOS CONECTORES
			try {
				// System.out.print("Valor minimo del peso las conexiones, [" +
				// pesoConectorMin + "]: ");
				// valorAct = teclado.readLine();
				pesoConectorMin = parameters.get("lowestConnectionWeigh");
			} catch (NumberFormatException e) {
			} finally {
				log("\tValor minimo del peso de las conexiones: " + pesoConectorMin);
			}

			// PESO MAXIMO DE LOS CONECTORES
			try {
				// System.out.print("Valor MAXIMO del peso las conexiones, [" +
				// pesoConectorMax + "]: ");
				// valorAct = teclado.readLine();
				pesoConectorMax = parameters.get("highestConnectionWeigh");
			} catch (NumberFormatException e) {
			} finally {
				log("\tValor MAXIMO del peso de las conexiones: " + pesoConectorMax);
			}

			// �SE UTILIZAN BIAS? (SI/NO)
			try {
				// System.out.print("Utilizar BIAS?, [" + BIAS + "]: ");
				// valorAct = teclado.readLine();
				opcion = BIAS ? 1 : 0;
				opcion = parameters.get("bias").intValue();
				BIAS = (opcion != 0) ? true : false;
			} catch (NumberFormatException e) {
			} finally {
				log("\tUtilizar BIAS?: " + BIAS);
			}

			// �SE NORMALIZA LA SALIDA DE LA RED? (SI/NO)
			try {
				// System.out.print("Normalizar la salida de la red?, [" +
				// SALIDA_NORMALIZADA + "]: ");
				// valorAct = teclado.readLine();
				opcion = SALIDA_NORMALIZADA ? 1 : 0;
				opcion = parameters.get("normalizedOutput").intValue();
				SALIDA_NORMALIZADA = (opcion != 0) ? true : false;
			} catch (NumberFormatException e) {
			} finally {
				log("\tNormalizar la salida de la red?: " + SALIDA_NORMALIZADA);
			}

			// RATIO DE APRENDIZAJE
			try {
				// System.out.print("Ratio de aprendizaje, [" +
				// RATIO_APRENDIZAJE + "]: ");
				// valorAct = teclado.readLine();
				RATIO_APRENDIZAJE = parameters.get("learningRate");
			} catch (NumberFormatException e) {
			} finally {
				log("\tRatio de aprendizaje: " + RATIO_APRENDIZAJE);
			}

			// MOMENTO
			try {
				// System.out.print("Momento, [" + momento + "]: ");
				// valorAct = teclado.readLine();
				momento = parameters.get("moment");
			} catch (NumberFormatException e) {
			} finally {
				log("\tMomento: " + momento);
			}

			// LAMBDA_1
			try {
				// System.out.print("Lambda_1, [" + LAMBDA1 + "]: ");
				// valorAct = teclado.readLine();
				LAMBDA1 = parameters.get("lambda1");
			} catch (NumberFormatException e) {
			} finally {
				deltaLambda1 = LAMBDA1 * 0.1F;
				log("\tLambda_1: " + LAMBDA1);
				log("\tRatio de disminucion de Lambda_1: " + deltaLambda1);
			}

			// LAMBDA_2
			try {
				// System.out.print("Lambda_2, [" + LAMBDA2 + "]: ");
				// valorAct = teclado.readLine();
				LAMBDA2 = parameters.get("lambda2");
			} catch (NumberFormatException e) {
			} finally {
				deltaLambda2 = LAMBDA2 * 0.1F;
				log("\tLambda_2: " + LAMBDA2);
				log("\tRatio de disminucion de Lambda_2: " + deltaLambda2);
			}

			// TOLERANCIA
			try {
				// System.out.print("Tolerancia permitida, [" + TOLERANCIA + "]:
				// ");
				// valorAct = teclado.readLine();
				TOLERANCIA = parameters.get("tolerance");
			} catch (NumberFormatException e) {
			} finally {
				log("\tTolerancia: " + TOLERANCIA);
			}

			// ERROR MEDIO MINIMO POR DEBAJO DEL CUAL SE PARA EL ENTRENAMIENTO
			try {
				// System.out.print("Error medio minimo limite de entrenamiento,
				// [" + MIN_ERROR_MED + "]: ");
				// valorAct = teclado.readLine();
				MIN_ERROR_MED = parameters.get("lowestErrorAverage");
			} catch (NumberFormatException e) {
			} finally {
				log("\tError medio minimo limite de entrenamiento: " + MIN_ERROR_MED);
			}

			// PORCENTAJE DE CAMBIO DE ERROR PARA LA INSERCION DE UN NUEVO
			// CENTRO
			try {
				// System.out.print("Variacion del error (%) para insercion de
				// nuevo centro, [" + ratioNuevoCentro + "]: ");
				// valorAct = teclado.readLine();
				ratioNuevoCentro = parameters.get("variationToInsertion");
			} catch (NumberFormatException e) {
			} finally {
				log("\tVariacion del error (%) para insercion de nuevo centro: " + ratioNuevoCentro);
			}

			// NUMERO INICIAL DE CENTROS
			try {
				// System.out.print("Numero inicial de centros, [3]: ");
				// valorAct = teclado.readLine();
				numNeuronasCentro = parameters.get("initialCenterNumber").intValue();
			} catch (NumberFormatException e) {
				numNeuronasCentro = 3;
			} finally {
				MIN_CENTROS = numNeuronasCentro;
				log("\tNumero inicial de centros: " + numNeuronasCentro);
			}

			// NUMERO MAXIMO DE CENTROS
			try {
				// System.out.print("Numero MAXIMO de centros, [50]: ");
				// valorAct = teclado.readLine();
				MAX_CENTROS = parameters.get("maxCentersNumber").intValue();
			} catch (NumberFormatException e) {
				MAX_CENTROS = 50;
			} finally {
				deltaCentros = MAX_CENTROS - numNeuronasCentro;
				log("\tNumero MAXIMO de centros: " + MAX_CENTROS);
			}

			// MAXIMO NUMERO DE ITERACIONES
			try {
				// System.out.print("Maximo numero de iteraciones, [500]: ");
				// valorAct = teclado.readLine();
				MAX_ITERACIONES = parameters.get("maxIterations").intValue();
			} catch (NumberFormatException e) {
				MAX_ITERACIONES = 500;
			} finally {
				log("\tNumero maximo de iteraciones: " + MAX_ITERACIONES);
			}

			log("\r\n\tComprobacion de insercion de nuevo centro cada " + ((MAX_ITERACIONES * RATIO_ITERAC_LIMITE / 100) / deltaCentros) + " iteraciones.");
			log("\tReduccion de LAMBDA1 y LAMBDA2 cada " + ((MAX_ITERACIONES * RATIO_ITERAC_LIMITE / 100) / 10) + " iteraciones.");
			log("");

			/*
			 * System.out.println("\r\n--------------------------------------------------------------");
			 * System.out.println("Comprobacion de insercion de nuevo centro
			 * cada " + ((MAX_ITERACIONES * RATIO_ITERAC_LIMITE / 100) /
			 * deltaCentros) + " iteraciones."); System.out.println("Reduccion
			 * de LAMBDA1 y LAMBDA2 cada " + ((MAX_ITERACIONES *
			 * RATIO_ITERAC_LIMITE / 100) / 10) + " iteraciones.");
			 * System.out.println("--------------------------------------------------------------");
			 */

			// Se construye la red
			generateNetwork(MIN_CENTROS);
		} catch (NumberFormatException ex) {
			ex.printStackTrace();
			ex.printStackTrace(new PrintWriter(fichLog));
		}
	}

	// GENERATENETWORK
	protected void generateNetwork(int num_centros) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -