📄 neuralfiledecoder.java
字号:
/*
* NeuralFileDecoder.java
*
* Created on 2007年11月29日, 上午11:39
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package Compressor;
import myUtil.*;
//import Compressor.FileAdapter;
import neuralNetwork.*;
import java.util.*;
import java.io.*;
import javax.swing.*;
/**
* decompress.
* @author yuhui_bear
*/
public class NeuralFileDecoder implements Runnable{
private Diagram showB;
private int branch =0 ;
private int[] net;
private long filelength=0;
private File networkFile ;
private BackPropagation compressNet;
private FileAdapter data= null;
private JProgressBar progressBar;
private JButton startBt;
/**
* Creates a new instance of NeuralEncoder.
* This one is just for testing.
* Trained net will be stored in .\"weight.xml.
* @param sb diaplay panel for the trainer.
* @param jb progress bar.
* @param source file to compress.
* @param br , Dendrites number of the neuron.
* @param top net information .
*/
public NeuralFileDecoder(Diagram sb ,JProgressBar jb ,File source, int br ,int[] top) {
progressBar = jb;
showB = sb; //new TestShowBoard(this);
branch =br;
net =top;
networkFile = new File("weight.xml");
compressNet = new BackPropagation(net,branch);
}
/**
* Creates a new instance of NeuralDecoder
* @param sb diagram to display MSE.
* @param jb progress bar.
* @param bt button been disabled on starting.
* @param source file to compress.
* @param orgnet neural net file.
*/
public NeuralFileDecoder(Diagram sb ,JProgressBar jb, JButton bt,File source, File orgnet ) {
progressBar = jb;
startBt = bt;
showB = sb; //new TestShowBoard(this);
networkFile = orgnet;
compressNet = new BackPropagation(orgnet);
net = compressNet.network.getNetInformation().nettop;
branch =compressNet.network.getNetInformation().branch;
//open the source file . prepare output file.
try {
data = new FileAdapter(source,net[net.length /2],false);
} catch (IOException ex) {
ex.printStackTrace();
System.exit(-1);
}
}
/**
* inherited for Runnable Interface.
*/
public void run(){
//prepare training swatch.
double[] inputdata = new double[net[0]];
double[] decoded = new double[net[net.length /2 +1]];
double[] outdata =new double[net[0]];
long work = data.getGroupSize();
int err=0;
while(work >0){
// get value ...
if(work ==2){
int ttt= 234;
ttt+=234;
}
inputdata = data.nextGroup();
decoded=compressNet.decode(inputdata);
showB.redraw(Evaluate.mean(decoded),"Remains="+(work--),"decoding...");
err = data.writeBack(decoded);
if(err==2){
break;
}
if(err <0){
System.err.print("write back error. err = "+ err);
System.exit(err);
}
progressBar.setValue((int)(100 * work / data.getGroupSize()));
}
data.writeBack(null);
showB.redraw(0 ,"Remains="+work,"done...");
progressBar.setValue(100);
startBt.setText("Job Done");
startBt.setEnabled(true);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -