|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Text; |
| 5 | + |
| 6 | +namespace Tensorflow.Clustering |
| 7 | +{ |
| 8 | + /// <summary> |
| 9 | + /// Internal class to create the op to initialize the clusters. |
| 10 | + /// </summary> |
| 11 | + public class _InitializeClustersOpFactory |
| 12 | + { |
| 13 | + Tensor[] _inputs; |
| 14 | + Tensor _num_clusters; |
| 15 | + IInitializer _initial_clusters; |
| 16 | + string _distance_metric; |
| 17 | + int _random_seed; |
| 18 | + int _kmeans_plus_plus_num_retries; |
| 19 | + int _kmc2_chain_length; |
| 20 | + RefVariable _cluster_centers; |
| 21 | + RefVariable _cluster_centers_updated; |
| 22 | + RefVariable _cluster_centers_initialized; |
| 23 | + Tensor _num_selected; |
| 24 | + Tensor _num_remaining; |
| 25 | + Tensor _num_data; |
| 26 | + |
| 27 | + public _InitializeClustersOpFactory(Tensor[] inputs, |
| 28 | + Tensor num_clusters, |
| 29 | + IInitializer initial_clusters, |
| 30 | + string distance_metric, |
| 31 | + int random_seed, |
| 32 | + int kmeans_plus_plus_num_retries, |
| 33 | + int kmc2_chain_length, |
| 34 | + RefVariable cluster_centers, |
| 35 | + RefVariable cluster_centers_updated, |
| 36 | + RefVariable cluster_centers_initialized) |
| 37 | + { |
| 38 | + _inputs = inputs; |
| 39 | + _num_clusters = num_clusters; |
| 40 | + _initial_clusters = initial_clusters; |
| 41 | + _distance_metric = distance_metric; |
| 42 | + _random_seed = random_seed; |
| 43 | + _kmeans_plus_plus_num_retries = kmeans_plus_plus_num_retries; |
| 44 | + _kmc2_chain_length = kmc2_chain_length; |
| 45 | + _cluster_centers = cluster_centers; |
| 46 | + _cluster_centers_updated = cluster_centers_updated; |
| 47 | + _cluster_centers_initialized = cluster_centers_initialized; |
| 48 | + |
| 49 | + _num_selected = array_ops.shape(_cluster_centers)[0]; |
| 50 | + _num_remaining = _num_clusters - _num_selected; |
| 51 | + |
| 52 | + _num_data = math_ops.add_n(_inputs.Select(i => array_ops.shape(i)[0]).ToArray()); |
| 53 | + } |
| 54 | + |
| 55 | + public Tensor[] op() |
| 56 | + { |
| 57 | + return control_flow_ops.cond(gen_math_ops.equal(_num_remaining, 0), |
| 58 | + () => new Operation[] { check_ops.assert_equal(_cluster_centers_initialized, true) }, |
| 59 | + () => new Operation[0]); |
| 60 | + } |
| 61 | + } |
| 62 | +} |
0 commit comments