MCPcopy Create free account
hub / github.com/DeepGraphLearning/graphvite / LargeVis

Class LargeVis

include/instance/model/visualization.h:34–86  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

32 */
33template<class _Vector>
34class LargeVis {
35public:
36 static const size_t dim = _Vector::dim;
37 typedef _Vector Vector;
38 typedef typename _Vector::Float Float;
39
40 __host__ __device__
41 static void forward(const Vector &head, const Vector &tail, Float &output) {
42 output = 0;
43 FOR(i, dim)
44 output += (head[i] - tail[i]) * (head[i] - tail[i]);
45 output = SUM(output);
46 }
47
48 template<OptimizerType optimizer_type>
49 __host__ __device__
50 static void backward(Vector &head, Vector &tail, Float gradient, const Optimizer &optimizer, Float weight = 1) {
51 auto update = get_update_function<Float, optimizer_type>();
52 FOR(i, dim) {
53 Float h = head[i];
54 Float t = tail[i];
55 head[i] -= (optimizer.*update)(h, gradient * (h - t), weight);
56 tail[i] -= (optimizer.*update)(t, gradient * (t - h), weight);
57 }
58 }
59
60 template<OptimizerType optimizer_type>
61 __host__ __device__
62 static void backward(Vector &head, Vector &tail, Vector &head_moment1, Vector &tail_moment1,
63 Float gradient, const Optimizer &optimizer, Float weight = 1) {
64 auto update = get_update_function_1_moment<Float, optimizer_type>();
65 FOR(i, dim) {
66 Float h = head[i];
67 Float t = tail[i];
68 head[i] -= (optimizer.*update)(h, gradient * (h - t), head_moment1[i], weight);
69 tail[i] -= (optimizer.*update)(t, gradient * (t - h), tail_moment1[i], weight);
70 }
71 }
72
73 template<OptimizerType optimizer_type>
74 __host__ __device__
75 static void backward(Vector &head, Vector &tail, Vector &head_moment1, Vector &tail_moment1,
76 Vector &head_moment2, Vector &tail_moment2,
77 Float gradient, const Optimizer &optimizer, Float weight = 1) {
78 auto update = get_update_function_2_moment<Float, optimizer_type>();
79 FOR(i, dim) {
80 Float h = head[i];
81 Float t = tail[i];
82 head[i] -= (optimizer.*update)(h, gradient * (h - t), head_moment1[i], head_moment2[i], weight);
83 tail[i] -= (optimizer.*update)(t, gradient * (t - h), tail_moment1[i], tail_moment2[i], weight);
84 }
85 }
86};
87
88}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected