def F(inputs): self.count += 1 R = fast_train_function(inputs) if self.count % self.k == 0: K.batch_get_value(slow_updates) K.batch_get_value(copy_updates) return R
def testLinearSolverConstruction(self, x1, y1, x2, y2, a, b): """ Verifies that a TFLinearEquationSolver is constructed correctly. """ solver = clustering_centroids.TFLinearEquationSolver( float(x1), float(y1), float(x2), float(y2)) solver_a = solver.a self.assertAlmostEqual(K.batch_get_value([solver_a])[0], a) self.assertAlmostEqual(K.batch_get_value([solver.b])[0], b)
def _pull_values(self, ca, pulling_indices, expected_output): pulling_indices_np = np.array(pulling_indices) res_tf = ca.get_clustered_weight(pulling_indices_np) res_np = K.batch_get_value([res_tf])[0] res_np_list = res_np.tolist() self.assertSequenceEqual(res_np_list, expected_output)
def testLinearSolverSolveForX(self, x1, y1, x2, y2, x, y): """ Verifies that TFLinearEquationSolver solves the given equations correctly for X. """ solver = clustering_centroids.TFLinearEquationSolver( float(x1), float(y1), float(x2), float(y2)) for_x = solver.solve_for_x(y) self.assertAlmostEqual(K.batch_get_value([for_x])[0], x)
def testCDFValues(self, weights, point, probability): """ Verifies that TFCumulativeDistributionFunction yields the expected output for the inputs provided. """ cdf_calc = clustering_centroids.TFCumulativeDistributionFunction( weights) self.assertAlmostEqual( probability, K.batch_get_value([cdf_calc.get_cdf_value(point)])[0])
def testLinearSolverSolveForY(self, x1, y1, x2, y2, x, y): solver = clustering_centroids.TFLinearEquationSolver( float(x1), float(y1), float(x2), float(y2)) for_y = solver.solve_for_y(x) self.assertAlmostEqual(K.batch_get_value([for_y])[0], y)
def testClusterCentroids(self, weights, number_of_clusters, centroids): dbci = clustering_centroids.DensityBasedCentroidsInitialisation( weights, number_of_clusters) calc_centroids = K.batch_get_value([dbci.get_cluster_centroids()])[0] self.assertSequenceAlmostEqual(centroids, calc_centroids, places=4)
def testCDFValues(self, weights, point, probability): cdf_calc = clustering_centroids.TFCumulativeDistributionFunction( weights) self.assertAlmostEqual( probability, K.batch_get_value([cdf_calc.get_cdf_value(point)])[0])