/** * wrap up various variables to save memeory and do some housekeeping after optimization has * finished. * * @throws Exception if something goes wrong */ protected void wrapUp() throws Exception { m_target = null; m_nEvals = m_kernel.numEvals(); m_nCacheHits = m_kernel.numCacheHits(); if ((m_SVM.getKernel() instanceof PolyKernel) && ((PolyKernel) m_SVM.getKernel()).getExponent() == 1.0) { // convert alpha's to weights double[] weights = new double[m_data.numAttributes()]; for (int k = m_supportVectors.getNext(-1); k != -1; k = m_supportVectors.getNext(k)) { for (int j = 0; j < weights.length; j++) { if (j != m_classIndex) { weights[j] += (m_alpha[k] - m_alphaStar[k]) * m_data.instance(k).value(j); } } } m_weights = weights; // release memory m_alpha = null; m_alphaStar = null; m_kernel = null; } m_bModelBuilt = true; }
public Kernel getProperKernel() { apiMatchedOnce = false; baseMatchedOnce = false; if (kernelSet.isEmpty()) { return null; } Iterator<Kernel> iterator = kernelSet.iterator(); while (iterator.hasNext()) { Kernel k = iterator.next(); try { boolean a = k.getBASE() .contains(preferences.getString(Keys.KEY_SETTINGS_ROMBASE, "").toUpperCase()); boolean b = k.getAPI().contains(preferences.getString(Keys.KEY_SETTINGS_ROMAPI, "").toUpperCase()); if (a) baseMatchedOnce = true; if (b) apiMatchedOnce = true; if (a & b) { if (!k.isTestBuild() || preferences.getBoolean(Keys.KEY_SETTINGS_LOOKFORBETA, false)) { return k; } } } catch (NullPointerException ignored) { } } return null; }
public void act() { Message message_NF; Message message_LFF; Message message_LFS; // Link failure handling if (failure_type == Link_F) { message_LFF = new Message(Values.interruptMessage, Values.ReachLoss, second_node); kernel.schedule( new ArrivalEventV2(first_node, message_LFF, kernel, GetTime.getNextSchedule(kernel))); message_LFS = new Message(Values.interruptMessage, Values.ReachLoss, first_node); kernel.schedule( new ArrivalEventV2(second_node, message_LFS, kernel, GetTime.getNextSchedule(kernel))); } // Node failure handling else { if (failure_type == Node_F) { NodeV2 Failed_Node = Topology.getNodeByAddressV2(failed_node); adjacenes = (TIntArrayList) (Failed_Node.getAdjacenes().clone()); Failed_Node.eraseState(); message_NF = new Message(Values.interruptMessage, Values.ReachLoss, failed_node); for (int i = 0; i < adjacenes.size(); i++) { kernel.schedule( new ArrivalEventV2( adjacenes.get(i), message_NF, kernel, GetTime.getNextSchedule(kernel))); } } else { } } }
// @Override public final double compute(final double[] x) { final int max, gs, d; double s; int i, e; gs = this.m_matDim; d = this.m_dimension; max = (d / (gs << 1)); s = 0d; e = 0; for (i = 0; i < max; i++) { s += Kernel.shiftedPermRotRastrigin( x, this.m_o, this.m_p, this.m_m, // e, gs, this.m_tmp); // e += gs; } return (s + Kernel.shiftedPermRastrigin(x, this.m_o, this.m_p, e, this.m_dimension - e)); }
@Test public void testIllegalRepoPaths() { String repo = "series://"; String docPath = repo + "x/x"; try { Kernel.getSeries() .createSeriesRepo(ContextFactory.getKernelUser(), repo, "SERIES {} using MEMORY {}"); fail("Cannot create a repository without an authority"); } catch (RaptureException e) { assertEquals("Cannot create a repository without an authority", e.getMessage()); } try { Kernel.getSeries() .createSeriesRepo(ContextFactory.getKernelUser(), "", "SERIES {} using MEMORY {}"); fail("URI cannot be null or empty"); } catch (RaptureException e) { assertEquals("Argument Repository URI cannot be null or empty", e.getMessage()); } try { Kernel.getSeries() .createSeriesRepo(ContextFactory.getKernelUser(), null, "SERIES {} using MEMORY {}"); fail("URI cannot be null or empty"); } catch (RaptureException e) { assertEquals("Argument Repository URI cannot be null or empty", e.getMessage()); } try { Kernel.getSeries() .createSeriesRepo(ContextFactory.getKernelUser(), docPath, "SERIES {} using MEMORY {}"); fail("Repository Uri can't have a document path component"); } catch (RaptureException e) { assertEquals("A Repository URI may not have a document path component", e.getMessage()); } }
/** Clone the data from the src type to the target */ @Override public void copyDocumentRepo( CallingContext context, String srcAuthority, String targAuthority, final Boolean wipe) { Repository srcRepo = Kernel.getKernel().getRepo(srcAuthority); // $NON-NLS-1$ final Repository targRepo = Kernel.getKernel().getRepo(targAuthority); // $NON-NLS-1$ if (wipe) { targRepo.drop(); } srcRepo.visitAll( "", null, new RepoVisitor() { //$NON-NLS-1$ @Override public boolean visit(String name, JsonContent content, boolean isFolder) { try { log.info(Messages.getString("Admin.Copying") + name); // $NON-NLS-1$ targRepo.addDocument( name, content.getContent(), "$copy", //$NON-NLS-1$ Messages.getString("Admin.CopyRepo"), wipe); //$NON-NLS-1$ } catch (RaptureException e) { log.info(Messages.getString("Admin.NoAddDoc") + name); // $NON-NLS-1$ } return true; } }); }
/** * initializes the algorithm * * @param data the data to work with * @throws Exception if m_SVM is null */ protected void init(Instances data) throws Exception { if (m_SVM == null) { throw new Exception("SVM not initialized in optimizer. Use RegOptimizer.setSVMReg()"); } m_C = m_SVM.getC(); m_data = data; m_classIndex = data.classIndex(); m_nInstances = data.numInstances(); // Initialize kernel m_kernel = Kernel.makeCopy(m_SVM.getKernel()); m_kernel.buildKernel(data); // init m_target m_target = new double[m_nInstances]; for (int i = 0; i < m_nInstances; i++) { m_target[i] = data.instance(i).classValue(); } m_random = new Random(m_nSeed); // initialize alpha and alpha* array to all zero m_alpha = new double[m_target.length]; m_alphaStar = new double[m_target.length]; m_supportVectors = new SMOset(m_nInstances); m_b = 0.0; m_nEvals = 0; m_nCacheHits = -1; }
@Before public void setup() { Kernel.INSTANCE.restart(); Kernel.initBootstrap(); if (!Kernel.getBlob().blobRepoExists(ctx, "//blobapitestrepo")) { Kernel.getBlob() .createBlobRepo( ctx, "//blobapitestrepo", "BLOB {} USING MEMORY {}", "REP {} USING MEMORY {}"); } }
/** Convolve with a 2D kernel */ public static void convolveHV( Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction) { int index = 0; float[] matrix = kernel.getKernelData(null); int rows = kernel.getHeight(); int cols = kernel.getWidth(); int rows2 = rows / 2; int cols2 = cols / 2; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float r = 0, g = 0, b = 0, a = 0; for (int row = -rows2; row <= rows2; row++) { int iy = y + row; int ioffset; if (0 <= iy && iy < height) ioffset = iy * width; else if (edgeAction == CLAMP_EDGES) ioffset = y * width; else if (edgeAction == WRAP_EDGES) ioffset = ((iy + height) % height) * width; else continue; int moffset = cols * (row + rows2) + cols2; for (int col = -cols2; col <= cols2; col++) { float f = matrix[moffset + col]; if (f != 0) { int ix = x + col; if (!(0 <= ix && ix < width)) { if (edgeAction == CLAMP_EDGES) ix = x; else if (edgeAction == WRAP_EDGES) ix = (x + width) % width; else continue; } int rgb = inPixels[ioffset + ix]; a += f * ((rgb >> 24) & 0xff); r += f * ((rgb >> 16) & 0xff); g += f * ((rgb >> 8) & 0xff); b += f * (rgb & 0xff); } } } int ia = alpha ? PixelUtils.clamp((int) (a + 0.5)) : 0xff; int ir = PixelUtils.clamp((int) (r + 0.5)); int ig = PixelUtils.clamp((int) (g + 0.5)); int ib = PixelUtils.clamp((int) (b + 0.5)); outPixels[index++] = (ia << 24) | (ir << 16) | (ig << 8) | ib; } } }
public static void convolve( Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction) { if (kernel.getHeight() == 1) convolveH(kernel, inPixels, outPixels, width, height, alpha, edgeAction); else if (kernel.getWidth() == 1) convolveV(kernel, inPixels, outPixels, width, height, alpha, edgeAction); else convolveHV(kernel, inPixels, outPixels, width, height, alpha, edgeAction); }
@Test public void testGetRepositories() { List<DocumentRepoConfig> documentRepositories = Kernel.getDoc().getDocRepoConfigs(callingContext); int preexisting = documentRepositories.size(); if (!Kernel.getDoc().docRepoExists(callingContext, repoUri)) { Kernel.getDoc().createDocRepo(callingContext, repoUri, config); } documentRepositories = Kernel.getDoc().getDocRepoConfigs(callingContext); assertEquals( JacksonUtil.jsonFromObject(documentRepositories), preexisting + 1, documentRepositories.size()); }
@Test public void testLastPoint() { String seriesName = "ticker"; String uri = String.format("%s/%s", REPO, seriesName); // add data points to series int total = 30; for (int i = 1; i <= total; i++) { Kernel.getSeries().addStringToSeries(ctx, uri, getColumn(i), getValue(i)); } // check last column SeriesPoint lastPoint = Kernel.getSeries().getLastPoint(ctx, uri); assertEquals(getColumn(total), lastPoint.getColumn()); }
/** Convolve with a kernel consisting of one column */ public static void convolveV( Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction) { int index = 0; float[] matrix = kernel.getKernelData(null); int rows = kernel.getHeight(); int rows2 = rows / 2; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { float r = 0, g = 0, b = 0, a = 0; for (int row = -rows2; row <= rows2; row++) { int iy = y + row; int ioffset; if (iy < 0) { if (edgeAction == CLAMP_EDGES) ioffset = 0; else if (edgeAction == WRAP_EDGES) ioffset = ((y + height) % height) * width; else ioffset = iy * width; } else if (iy >= height) { if (edgeAction == CLAMP_EDGES) ioffset = (height - 1) * width; else if (edgeAction == WRAP_EDGES) ioffset = ((y + height) % height) * width; else ioffset = iy * width; } else ioffset = iy * width; float f = matrix[row + rows2]; if (f != 0) { int rgb = inPixels[ioffset + x]; a += f * ((rgb >> 24) & 0xff); r += f * ((rgb >> 16) & 0xff); g += f * ((rgb >> 8) & 0xff); b += f * (rgb & 0xff); } } int ia = alpha ? PixelUtils.clamp((int) (a + 0.5)) : 0xff; int ir = PixelUtils.clamp((int) (r + 0.5)); int ig = PixelUtils.clamp((int) (g + 0.5)); int ib = PixelUtils.clamp((int) (b + 0.5)); outPixels[index++] = (ia << 24) | (ir << 16) | (ig << 8) | ib; } } }
/** * SVMOutput of an instance in the training set, m_data This uses the cache, unlike * SVMOutput(Instance) * * @param index index of the training instance in m_data * @return the SVM output * @throws Exception if something goes wrong */ protected double SVMOutput(int index) throws Exception { double result = -m_b; for (int i = m_supportVectors.getNext(-1); i != -1; i = m_supportVectors.getNext(i)) { result += (m_alpha[i] - m_alphaStar[i]) * m_kernel.eval(index, i, m_data.instance(index)); } return result; }
/** * Compute the value of the objective function. * * @return the score * @throws Exception if something goes wrong */ protected double getScore() throws Exception { double res = 0; double t = 0, t2 = 0; double sumAlpha = 0.0; for (int i = 0; i < m_nInstances; i++) { sumAlpha += (m_alpha[i] - m_alphaStar[i]); for (int j = 0; j < m_nInstances; j++) { t += (m_alpha[i] - m_alphaStar[i]) * (m_alpha[j] - m_alphaStar[j]) * m_kernel.eval(i, j, m_data.instance(i)); } // switch(m_nLossType) { // case L1: // t2 += m_data.instance(i).classValue() * (m_alpha[i] - m_alpha_[i]); // break; // case L2: // t2 += m_data.instance(i).classValue() * (m_alpha[i] - m_alpha_[i]) - (0.5/m_SVM.getC()) // * (m_alpha[i]*m_alpha[i] + m_alpha_[i]*m_alpha_[i]); // break; // case HUBER: // t2 += m_data.instance(i).classValue() * (m_alpha[i] - m_alpha_[i]) - // (0.5*m_SVM.getEpsilon()/m_SVM.getC()) * (m_alpha[i]*m_alpha[i] + m_alpha_[i]*m_alpha_[i]); // break; // case EPSILON: // t2 += m_data.instance(i).classValue() * (m_alpha[i] - m_alphaStar[i]) - m_epsilon * // (m_alpha[i] + m_alphaStar[i]); t2 += m_target[i] * (m_alpha[i] - m_alphaStar[i]) - m_epsilon * (m_alpha[i] + m_alphaStar[i]); // break; // } } res += -0.5 * t + t2; return res; }
@Test public void testStandardTemplate() { ConfigLoader.getConf().StandardTemplate = "NREP {} USING MEMORY { prefix=\"${partition}.${type}\"}"; Repository repo = Kernel.getKernel().getRepo("repoNotYetCreated"); assertNotNull(repo); }
/** Convolve with a kernel consisting of one row */ public static void convolveH( Kernel kernel, int[] inPixels, int[] outPixels, int width, int height, boolean alpha, int edgeAction) { int index = 0; float[] matrix = kernel.getKernelData(null); int cols = kernel.getWidth(); int cols2 = cols / 2; for (int y = 0; y < height; y++) { int ioffset = y * width; for (int x = 0; x < width; x++) { float r = 0, g = 0, b = 0, a = 0; int moffset = cols2; for (int col = -cols2; col <= cols2; col++) { float f = matrix[moffset + col]; if (f != 0) { int ix = x + col; if (ix < 0) { if (edgeAction == CLAMP_EDGES) ix = 0; else if (edgeAction == WRAP_EDGES) ix = (x + width) % width; } else if (ix >= width) { if (edgeAction == CLAMP_EDGES) ix = width - 1; else if (edgeAction == WRAP_EDGES) ix = (x + width) % width; } int rgb = inPixels[ioffset + ix]; a += f * ((rgb >> 24) & 0xff); r += f * ((rgb >> 16) & 0xff); g += f * ((rgb >> 8) & 0xff); b += f * (rgb & 0xff); } } int ia = alpha ? PixelUtils.clamp((int) (a + 0.5)) : 0xff; int ir = PixelUtils.clamp((int) (r + 0.5)); int ig = PixelUtils.clamp((int) (g + 0.5)); int ib = PixelUtils.clamp((int) (b + 0.5)); outPixels[index++] = (ia << 24) | (ir << 16) | (ig << 8) | ib; } } }
// @Override public final double compute(final double[] x) { return (Kernel.shiftedPermRotAckley( x, this.m_o, this.m_p, this.m_m, // 0, this.m_matDim, this.m_tmp) * 1e6) + // Kernel.shiftedPermAckley( x, this.m_o, this.m_p, this.m_matDim, // this.m_dimension - this.m_matDim); }
/** * Should be called with extreme caution and only when a process is sure it is not already * scheduled. */ public void schedule(Kernel simulator, double time) { if (!scheduled) { nextSchedule = time; simulator.schedule(this); scheduled = true; } else // Const.error("Wrong scheduling in Unit"); System.out.println("Wrong scheduling in Unit"); }
@Before public void setUp() { RaptureConfig.setLoadYaml(false); Kernel.initBootstrap(); this.repo = new RepoApiImpl(Kernel.INSTANCE); this.callingContext = new CallingContext(); this.callingContext.setUser("dummy"); Kernel.INSTANCE.clearRepoCache(false); }
@Test public void deleteSeriesByUriPrefixTest() { ensureRepo(REPO); ensureSeries(REPO, "top"); ensureSeries(REPO, "live/series"); ensureSeries(REPO, "die/series"); ensureSeries(REPO, "nested/die/series"); ensureSeries(REPO, "die/nested/series"); Kernel.getSeries().deleteSeriesByUriPrefix(ctx, REPO + "/die"); }
/** * A kernel is a group of cars that are switched as a unit. * * @param kernel */ public void setKernel(Kernel kernel) { if (_kernel == kernel) { return; } String old = ""; if (_kernel != null) { old = _kernel.getName(); _kernel.delete(this); } _kernel = kernel; String newName = ""; if (_kernel != null) { _kernel.add(this); newName = _kernel.getName(); } if (!old.equals(newName)) { setDirtyAndFirePropertyChange(KERNEL_NAME_CHANGED_PROPERTY, old, newName); // NOI18N } }
private void sendReport() { Intent intent = new Intent(Intent.ACTION_SENDTO); Uri uri = Uri.parse("mailto:[email protected]?subject=Bugreport"); intent.setData(uri); StringBuilder text = new StringBuilder(); text.append("Manufacturer = " + Build.MANUFACTURER + "\n"); text.append("Modell = " + Build.MODEL + "\n"); text.append("Android version = " + Build.VERSION.RELEASE + "\n"); String logcat = Kernel.getLogcat(); if (logcat != null) { text.append("Logcat:\n"); text.append(logcat); } String dir = Kernel.showSystem(); if (dir != null) { text.append("System:\n"); text.append(dir); } ArrayList<String> mount = new ArrayList<String>(); Kernel.addSDMount(mount); if (mount.size() > 0) { text.append("Mounts:\n"); for (String line : mount) { text.append(line); } } intent.putExtra(Intent.EXTRA_TEXT, text.toString()); try { startActivity(Intent.createChooser(intent, "Send bugreport")); } catch (ActivityNotFoundException e) { Log.w(Utils.TAG, "No activity found: " + e.toString()); } }
private static int getProcessId(Process process) { int PID = 0; if (process.getClass().getName().equals("java.lang.Win32Process") || process.getClass().getName().equals("java.lang.ProcessImpl")) { try { Field f = process.getClass().getDeclaredField("handle"); f.setAccessible(true); long handl = f.getLong(process); Kernel kernel = Kernel.INSTANCE; W32API.HANDLE handle = new W32API.HANDLE(); handle.setPointer(Pointer.createConstant(handl)); PID = kernel.GetProcessId(handle); } catch (Throwable e) { Loggers.SERVER.error("PID PROBLEM " + e); } } return PID; }
/** * Builds a model using the current Kernel using the given data and returns the produced output. * * @param data the instances to test the Kernel on * @return a String containing the output of the Kernel. */ protected String useKernel(Instances data) throws Exception { Kernel kernel = null; StringBuffer text = new StringBuffer(); try { kernel = Kernel.makeCopy(m_Kernel); } catch (Exception e) { e.printStackTrace(); fail("Problem setting up to use Kernel: " + e); } kernel.buildKernel(data); for (int n = 0; n < data.numInstances(); n++) { for (int i = n; i < data.numInstances(); i++) { text.append((n + 1) + "-" + (i + 1) + ": " + kernel.eval(n, i, data.instance(i)) + "\n"); } } return text.toString(); }
void swap_index(int i, int j) { Q.swap_index(i,j); do {byte _=y[i]; y[i]=y[j]; y[j]=_;} while(false); do {double _=G[i]; G[i]=G[j]; G[j]=_;} while(false); do {byte _=alpha_status[i]; alpha_status[i]=alpha_status[j]; alpha_status[j]=_;} while(false); do {double _=alpha[i]; alpha[i]=alpha[j]; alpha[j]=_;} while(false); do {double _=b[i]; b[i]=b[j]; b[j]=_;} while(false); do {int _=active_set[i]; active_set[i]=active_set[j]; active_set[j]=_;} while(false); do {double _=G_bar[i]; G_bar[i]=G_bar[j]; G_bar[j]=_;} while(false); }
@Test public void testPutBlob() { Kernel.getBlob().putBlob(ctx, "//blobapitestrepo/x", "xy".getBytes(), "text/plain"); Kernel.getBlob().putBlob(ctx, "blob://blobapitestrepo/y", "zz".getBytes(), "text/plain"); assertNotNull(Kernel.getBlob().getBlob(ctx, "//blobapitestrepo/x")); assertNotNull(Kernel.getBlob().getBlob(ctx, "blob://blobapitestrepo/x")); assertNotNull(Kernel.getBlob().getBlob(ctx, "//blobapitestrepo/y")); assertNotNull(Kernel.getBlob().getBlob(ctx, "blob://blobapitestrepo/y")); }
private void updateOpenCL(float tpf) { // advect time time += tpf; // aquire resource buffer.acquireBufferForSharingNoEvent(clQueue); // no need to wait for the returned event, since the kernel implicitely waits for it (same // command queue) // execute kernel float scale = (float) Math.pow(1.1, (1.0 - time % 2) / 16.0); kernel.Run1NoEvent(clQueue, ws, buffer, scale); // release resource buffer.releaseBufferForSharingNoEvent(clQueue); }
/** * c1 and c2 must be Nodes. if the nodeType field is set, the type of the Nodes must match * nodeType field for us to evaluate the delegateKernel on them. * * @return sum( sum( K(child(i),child(j) ) ) ) */ public double evaluate(Object c1, Object c2) { Node n1 = (Node) c1; Node n2 = (Node) c2; double d = 0; for (Node child1 : n1.getChildren()) { for (Node child2 : n2.getChildren()) { // if node type specified, they have to match if (getNodeType() == null || (getNodeType().equals(child1.getType()) && getNodeType().equals(child2.getType()))) { d += delegateKernel.evaluate(child1, child2); } } } if (pow > 1) return Math.pow(d, pow); else return d; }
/** * @param inst * @return * @throws Exception */ public double SVMOutput(Instance inst) throws Exception { double result = -m_b; // Is the machine linear? if (m_weights != null) { // Is weight vector stored in sparse format? for (int i = 0; i < m_weights.length; i++) { if (inst.index(i) != m_classIndex) { result += m_weights[inst.index(i)] * inst.valueSparse(i); } } } else { for (int i = m_supportVectors.getNext(-1); i != -1; i = m_supportVectors.getNext(i)) { result += (m_alpha[i] - m_alphaStar[i]) * m_kernel.eval(-1, i, inst); } } return result; }