/** Normalises the data in the specified array to be in range [0,1], with * 0 as the minimum, and 1 as the maximum. RETURNS THE SAME ARRAY OBJECT * - i.e. changes are made in place. * @param data */ public static float[] standardNormalisation(final float[] data) { final int l = data.length; if (l==0) return data; final float min = min(data); final float max = max(data); if (max == 0 && min == 0) return data; final float product = (max != min) ? 1.0f/ ( max - min) : 1.f/max; for(int i=0;i<l;i++) { data[i] = (data[i] - min) * product; } return data; }
loadOOS(params[1]); loadOOS(params[1]); map = false; staticMap = null; FstaticMap = null; if (params.length == 4) loadDocid2score(Integer.parseInt(params[1]), params[2], Integer.parseInt(params[3])); else loadDocid2score(Integer.parseInt(params[1]), params[2], 2); source = params[2]; map = false; staticMap = null; FstaticMap = null; if (params.length == 4) loadScorefile(Integer.parseInt(params[1]), params[2], Integer.parseInt(params[3])); else loadScorefile(Integer.parseInt(params[1]), params[2], 1); source = params[2]; map = true; FstaticMap = null; loadOOS_Map(params[1]); source = "tmap"; standardNormalisation(FstaticScores); else StaTools.standardNormalisation(staticScores);
protected void loadfloatOOS(String inputFile) { logger.info("Opening OOS feature file " + inputFile); try { java.io.ObjectInputStream ois = new java.io.ObjectInputStream(Files.openFileStream(inputFile)); Object o = ois.readObject(); if (o instanceof float[]) FstaticScores = (float[]) o; else if (o instanceof double[]) FstaticScores = castToFloatArr((double[]) o); else if (o instanceof short[]) FstaticScores = castToFloatArr((short[]) o); else throw new ClassCastException("Inputfile contained " + o.getClass().getName() + " expected double[], short[] or float[]"); printStats(staticScores); ois.close(); } catch (Exception e) { logger.error("Problem opening file: \""+inputFile+"\"", e); } }
protected void loadOOS(String inputFile) { logger.info("Opening OOS feature file " + inputFile); try { java.io.ObjectInputStream ois = new java.io.ObjectInputStream(Files.openFileStream(inputFile)); Object o = ois.readObject(); if (o instanceof double[]) staticScores = (double[]) o; else if (o instanceof float[]) staticScores = castToDoubleArr((float[]) o); else if (o instanceof short[]) staticScores = castToDoubleArr((short[]) o); else throw new ClassCastException("Inputfile contained " + o.getClass().getName() + " expected double[], short[] or float[]"); printStats(staticScores); ois.close(); } catch (Exception e) { logger.error("Problem opening file: \""+inputFile+"\"", e); } }
protected void loadDocid2score(int numDocs, String inputFile, final int column) { logger.info("Opening docid2score feature file " + inputFile); try { String line = null; BufferedReader br = Files.openFileReader(inputFile); staticScores = new double[numDocs]; while((line = br.readLine())!= null) { final String[] parts = SPLIT_SPACE.split(line, column+1); staticScores[Integer.parseInt(parts[0])] = Double.parseDouble(parts[column-1]); } printStats(staticScores); br.close(); } catch (Exception e) { System.err.println("Problem opening file: \""+inputFile+"\" : "+e); e.printStackTrace(); } }
loadOOS(params[1]); loadOOS(params[1]); map = false; staticMap = null; FstaticMap = null; if (params.length == 4) loadDocid2score(Integer.parseInt(params[1]), params[2], Integer.parseInt(params[3])); else loadDocid2score(Integer.parseInt(params[1]), params[2], 2); source = params[2]; map = false; staticMap = null; FstaticMap = null; if (params.length == 4) loadScorefile(Integer.parseInt(params[1]), params[2], Integer.parseInt(params[3])); else loadScorefile(Integer.parseInt(params[1]), params[2], 1); source = params[2]; map = true; FstaticMap = null; loadOOS_Map(params[1]); source = "tmap"; standardNormalisation(FstaticScores); else StaTools.standardNormalisation(staticScores);
protected void loadfloatOOS(String inputFile) { logger.info("Opening OOS feature file " + inputFile); try { java.io.ObjectInputStream ois = new java.io.ObjectInputStream(Files.openFileStream(inputFile)); Object o = ois.readObject(); if (o instanceof float[]) FstaticScores = (float[]) o; else if (o instanceof double[]) FstaticScores = castToFloatArr((double[]) o); else if (o instanceof short[]) FstaticScores = castToFloatArr((short[]) o); else throw new ClassCastException("Inputfile contained " + o.getClass().getName() + " expected double[], short[] or float[]"); printStats(staticScores); ois.close(); } catch (Exception e) { logger.error("Problem opening file: \""+inputFile+"\"", e); } }
protected void loadOOS(String inputFile) { logger.info("Opening OOS feature file " + inputFile); try { java.io.ObjectInputStream ois = new java.io.ObjectInputStream(Files.openFileStream(inputFile)); Object o = ois.readObject(); if (o instanceof double[]) staticScores = (double[]) o; else if (o instanceof float[]) staticScores = castToDoubleArr((float[]) o); else if (o instanceof short[]) staticScores = castToDoubleArr((short[]) o); else throw new ClassCastException("Inputfile contained " + o.getClass().getName() + " expected double[], short[] or float[]"); printStats(staticScores); ois.close(); } catch (Exception e) { logger.error("Problem opening file: \""+inputFile+"\"", e); } }
protected void loadDocid2score(int numDocs, String inputFile, final int column) { logger.info("Opening docid2score feature file " + inputFile); try { String line = null; BufferedReader br = Files.openFileReader(inputFile); staticScores = new double[numDocs]; while((line = br.readLine())!= null) { final String[] parts = SPLIT_SPACE.split(line, column+1); staticScores[Integer.parseInt(parts[0])] = Double.parseDouble(parts[column-1]); } printStats(staticScores); br.close(); } catch (Exception e) { System.err.println("Problem opening file: \""+inputFile+"\" : "+e); e.printStackTrace(); } }
/** Normalises the data in the specified array to be in range [0,1], with * 0 as the minimum, and 1 as the maximum. RETURNS THE SAME ARRAY OBJECT * - i.e. changes are made in place. * @param data */ public static float[] standardNormalisation(final float[] data) { final int l = data.length; if (l==0) return data; final float min = min(data); final float max = max(data); if (max == 0 && min == 0) return data; final float product = (max != min) ? 1.0f/ ( max - min) : 1.f/max; for(int i=0;i<l;i++) { data[i] = (data[i] - min) * product; } return data; }