mirror of
https://github.com/Relintai/pmlpp.git
synced 2024-11-08 13:12:09 +01:00
Include sfw if it's an sfw build.
This commit is contained in:
parent
5218d2296a
commit
3f9c7a2db3
@ -267,6 +267,10 @@ Help(opts.GenerateHelpText(env_base))
|
||||
# add default include paths
|
||||
|
||||
env_base.Prepend(CPPPATH=["#"])
|
||||
env_base.Prepend(CPPPATH=["#platform"])
|
||||
|
||||
# USE SFWL
|
||||
env_base.Prepend(CPPDEFINES=["USING_SFW"])
|
||||
|
||||
# configure ENV for platform
|
||||
env_base.platform_exporters = platform_exporters
|
||||
|
@ -31,8 +31,6 @@
|
||||
#include "activation.h"
|
||||
#include "../lin_alg/lin_alg.h"
|
||||
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
@ -31,11 +31,17 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/func_ref.h"
|
||||
#include "core/object/reference.h"
|
||||
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
|
||||
|
@ -35,7 +35,12 @@
|
||||
#include "../lin_alg/lin_alg.h"
|
||||
#include "../regularization/reg.h"
|
||||
#include "../utilities/utilities.h"
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/log/logger.h"
|
||||
#endif
|
||||
|
||||
#include <random>
|
||||
|
||||
|
@ -31,10 +31,16 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_tensor3.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
|
@ -34,7 +34,11 @@
|
||||
#include "../cost/cost.h"
|
||||
#include "../utilities/utilities.h"
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/log/logger.h"
|
||||
#endif
|
||||
|
||||
#include <random>
|
||||
|
||||
|
@ -31,9 +31,12 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
|
@ -31,11 +31,15 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/containers/hash_map.h"
|
||||
#include "core/containers/vector.h"
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
|
@ -31,10 +31,15 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
|
||||
#endif
|
||||
|
||||
#include "../regularization/reg.h"
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
|
@ -31,7 +31,12 @@
|
||||
#include "convolutions.h"
|
||||
#include "../lin_alg/lin_alg.h"
|
||||
#include "../stat/stat.h"
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_funcs.h"
|
||||
#endif
|
||||
|
||||
#include <cmath>
|
||||
|
||||
|
@ -31,16 +31,22 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/containers/vector.h"
|
||||
#include "core/string/ustring.h"
|
||||
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_tensor3.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
|
||||
|
||||
class MLPPConvolutions : public Reference {
|
||||
GDCLASS(MLPPConvolutions, Reference);
|
||||
|
@ -31,9 +31,13 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
|
||||
|
@ -30,7 +30,11 @@
|
||||
|
||||
#include "data.h"
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/os/file_access.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/lin_alg.h"
|
||||
#include "../stat/stat.h"
|
||||
|
@ -31,12 +31,16 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/variant/array.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
|
@ -35,9 +35,13 @@
|
||||
// http://ciml.info/dl/v0_99/ciml-v0_99-ch11.pdf
|
||||
// Were excellent for the practical intution behind the dual formulation.
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
|
@ -31,9 +31,13 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../regularization/reg.h"
|
||||
|
||||
|
@ -34,7 +34,11 @@
|
||||
#include "../regularization/reg.h"
|
||||
#include "../utilities/utilities.h"
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/log/logger.h"
|
||||
#endif
|
||||
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
@ -31,9 +31,13 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../hidden_layer/hidden_layer.h"
|
||||
#include "../output_layer/output_layer.h"
|
||||
|
@ -31,9 +31,13 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
@ -30,7 +30,11 @@
|
||||
|
||||
#include "gaussian_nb.h"
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
#endif
|
||||
|
||||
#include "../stat/stat.h"
|
||||
#include "../utilities/utilities.h"
|
||||
|
@ -31,9 +31,13 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
|
@ -31,10 +31,14 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
#include "core/string/ustring.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../activation/activation.h"
|
||||
#include "../regularization/reg.h"
|
||||
|
@ -31,9 +31,13 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include <tuple>
|
||||
#include <vector>
|
||||
|
@ -31,7 +31,11 @@
|
||||
#include "kmeans.h"
|
||||
#include "../utilities/utilities.h"
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/random_pcg.h"
|
||||
#endif
|
||||
|
||||
#include <climits>
|
||||
#include <iostream>
|
||||
|
@ -31,9 +31,13 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
|
@ -31,8 +31,12 @@
|
||||
#include "knn.h"
|
||||
#include "../utilities/utilities.h"
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/containers/hash_map.h"
|
||||
#include "core/containers/vector.h"
|
||||
#endif
|
||||
|
||||
Ref<MLPPMatrix> MLPPKNN::get_input_set() {
|
||||
return _input_set;
|
||||
|
@ -31,9 +31,13 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
|
@ -30,7 +30,11 @@
|
||||
|
||||
#include "lin_alg.h"
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_funcs.h"
|
||||
#endif
|
||||
|
||||
#include "../stat/stat.h"
|
||||
#include <cmath>
|
||||
|
@ -33,19 +33,12 @@
|
||||
|
||||
//TODO Methods here should probably use error macros in a way where they get disabled in non-tools(?) (maybe release?) builds
|
||||
|
||||
#ifndef GDNATIVE
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
|
||||
#else
|
||||
|
||||
#include "core/defs.h"
|
||||
#include "core/math_funcs.h"
|
||||
|
||||
#include "gen/resource.h"
|
||||
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
|
@ -30,7 +30,11 @@
|
||||
|
||||
#include "mlpp_matrix.h"
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/io/image.h"
|
||||
#endif
|
||||
|
||||
#include "../stat/stat.h"
|
||||
#include <random>
|
||||
|
@ -1,6 +1,5 @@
|
||||
#ifndef MLPP_MATRIX_H
|
||||
#define MLPP_MATRIX_H
|
||||
#ifndef GDNATIVE
|
||||
|
||||
/*************************************************************************/
|
||||
/* mlpp_matrix.h */
|
||||
@ -32,6 +31,9 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/containers/pool_vector.h"
|
||||
@ -42,17 +44,6 @@
|
||||
#include "core/os/memory.h"
|
||||
|
||||
#include "core/object/resource.h"
|
||||
|
||||
#else
|
||||
|
||||
#include "core/containers/vector.h"
|
||||
#include "core/defs.h"
|
||||
#include "core/math_funcs.h"
|
||||
#include "core/os/memory.h"
|
||||
#include "core/pool_arrays.h"
|
||||
|
||||
#include "gen/resource.h"
|
||||
|
||||
#endif
|
||||
|
||||
#include "mlpp_vector.h"
|
||||
@ -60,355 +51,359 @@
|
||||
class Image;
|
||||
|
||||
class MLPPMatrix : public Resource {
|
||||
GDCLASS(MLPPMatrix, Resource);
|
||||
GDCLASS(MLPPMatrix, Resource);
|
||||
|
||||
public:
|
||||
Array get_data();
|
||||
void set_data(const Array &p_from);
|
||||
Array get_data();
|
||||
void set_data(const Array &p_from);
|
||||
|
||||
_FORCE_INLINE_ real_t *ptrw() {
|
||||
return _data;
|
||||
}
|
||||
_FORCE_INLINE_ real_t *ptrw() { return _data; }
|
||||
|
||||
_FORCE_INLINE_ const real_t *ptr() const {
|
||||
return _data;
|
||||
}
|
||||
_FORCE_INLINE_ const real_t *ptr() const { return _data; }
|
||||
|
||||
void row_add(const Vector<real_t> &p_row);
|
||||
void row_add_pool_vector(const PoolRealArray &p_row);
|
||||
void row_add_mlpp_vector(const Ref<MLPPVector> &p_row);
|
||||
void rows_add_mlpp_matrix(const Ref<MLPPMatrix> &p_other);
|
||||
void row_add(const Vector<real_t> &p_row);
|
||||
void row_add_pool_vector(const PoolRealArray &p_row);
|
||||
void row_add_mlpp_vector(const Ref<MLPPVector> &p_row);
|
||||
void rows_add_mlpp_matrix(const Ref<MLPPMatrix> &p_other);
|
||||
|
||||
void row_remove(int p_index);
|
||||
void row_remove(int p_index);
|
||||
|
||||
// Removes the item copying the last value into the position of the one to
|
||||
// remove. It's generally faster than `remove`.
|
||||
void row_remove_unordered(int p_index);
|
||||
// Removes the item copying the last value into the position of the one to
|
||||
// remove. It's generally faster than `remove`.
|
||||
void row_remove_unordered(int p_index);
|
||||
|
||||
void row_swap(int p_index_1, int p_index_2);
|
||||
void row_swap(int p_index_1, int p_index_2);
|
||||
|
||||
_FORCE_INLINE_ void clear() { resize(Size2i()); }
|
||||
_FORCE_INLINE_ void reset() {
|
||||
if (_data) {
|
||||
memfree(_data);
|
||||
_data = NULL;
|
||||
_size = Vector2i();
|
||||
}
|
||||
}
|
||||
_FORCE_INLINE_ void clear() { resize(Size2i()); }
|
||||
_FORCE_INLINE_ void reset() {
|
||||
if (_data) {
|
||||
memfree(_data);
|
||||
_data = NULL;
|
||||
_size = Vector2i();
|
||||
}
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool empty() const { return data_size() == 0; }
|
||||
_FORCE_INLINE_ int data_size() const { return _size.x * _size.y; }
|
||||
_FORCE_INLINE_ Size2i size() const { return _size; }
|
||||
_FORCE_INLINE_ bool empty() const { return data_size() == 0; }
|
||||
_FORCE_INLINE_ int data_size() const { return _size.x * _size.y; }
|
||||
_FORCE_INLINE_ Size2i size() const { return _size; }
|
||||
|
||||
void resize(const Size2i &p_size);
|
||||
void resize(const Size2i &p_size);
|
||||
|
||||
_FORCE_INLINE_ int calculate_index(int p_index_y, int p_index_x) const {
|
||||
return p_index_y * _size.x + p_index_x;
|
||||
}
|
||||
_FORCE_INLINE_ int calculate_index(int p_index_y, int p_index_x) const {
|
||||
return p_index_y * _size.x + p_index_x;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ const real_t &operator[](int p_index) const {
|
||||
CRASH_BAD_INDEX(p_index, data_size());
|
||||
return _data[p_index];
|
||||
}
|
||||
_FORCE_INLINE_ real_t &operator[](int p_index) {
|
||||
CRASH_BAD_INDEX(p_index, data_size());
|
||||
return _data[p_index];
|
||||
}
|
||||
_FORCE_INLINE_ const real_t &operator[](int p_index) const {
|
||||
CRASH_BAD_INDEX(p_index, data_size());
|
||||
return _data[p_index];
|
||||
}
|
||||
_FORCE_INLINE_ real_t &operator[](int p_index) {
|
||||
CRASH_BAD_INDEX(p_index, data_size());
|
||||
return _data[p_index];
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ real_t element_get_index(int p_index) const {
|
||||
ERR_FAIL_INDEX_V(p_index, data_size(), 0);
|
||||
_FORCE_INLINE_ real_t element_get_index(int p_index) const {
|
||||
ERR_FAIL_INDEX_V(p_index, data_size(), 0);
|
||||
|
||||
return _data[p_index];
|
||||
}
|
||||
return _data[p_index];
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void element_set_index(int p_index, real_t p_val) {
|
||||
ERR_FAIL_INDEX(p_index, data_size());
|
||||
_FORCE_INLINE_ void element_set_index(int p_index, real_t p_val) {
|
||||
ERR_FAIL_INDEX(p_index, data_size());
|
||||
|
||||
_data[p_index] = p_val;
|
||||
}
|
||||
_data[p_index] = p_val;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ real_t element_get(int p_index_y, int p_index_x) const {
|
||||
ERR_FAIL_INDEX_V(p_index_x, _size.x, 0);
|
||||
ERR_FAIL_INDEX_V(p_index_y, _size.y, 0);
|
||||
_FORCE_INLINE_ real_t element_get(int p_index_y, int p_index_x) const {
|
||||
ERR_FAIL_INDEX_V(p_index_x, _size.x, 0);
|
||||
ERR_FAIL_INDEX_V(p_index_y, _size.y, 0);
|
||||
|
||||
return _data[p_index_y * _size.x + p_index_x];
|
||||
}
|
||||
return _data[p_index_y * _size.x + p_index_x];
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void element_set(int p_index_y, int p_index_x, real_t p_val) {
|
||||
ERR_FAIL_INDEX(p_index_x, _size.x);
|
||||
ERR_FAIL_INDEX(p_index_y, _size.y);
|
||||
_FORCE_INLINE_ void element_set(int p_index_y, int p_index_x, real_t p_val) {
|
||||
ERR_FAIL_INDEX(p_index_x, _size.x);
|
||||
ERR_FAIL_INDEX(p_index_y, _size.y);
|
||||
|
||||
_data[p_index_y * _size.x + p_index_x] = p_val;
|
||||
}
|
||||
_data[p_index_y * _size.x + p_index_x] = p_val;
|
||||
}
|
||||
|
||||
Vector<real_t> row_get_vector(int p_index_y) const;
|
||||
PoolRealArray row_get_pool_vector(int p_index_y) const;
|
||||
Ref<MLPPVector> row_get_mlpp_vector(int p_index_y) const;
|
||||
void row_get_into_mlpp_vector(int p_index_y, Ref<MLPPVector> target) const;
|
||||
Vector<real_t> row_get_vector(int p_index_y) const;
|
||||
PoolRealArray row_get_pool_vector(int p_index_y) const;
|
||||
Ref<MLPPVector> row_get_mlpp_vector(int p_index_y) const;
|
||||
void row_get_into_mlpp_vector(int p_index_y, Ref<MLPPVector> target) const;
|
||||
|
||||
void row_set_vector(int p_index_y, const Vector<real_t> &p_row);
|
||||
void row_set_pool_vector(int p_index_y, const PoolRealArray &p_row);
|
||||
void row_set_mlpp_vector(int p_index_y, const Ref<MLPPVector> &p_row);
|
||||
void row_set_vector(int p_index_y, const Vector<real_t> &p_row);
|
||||
void row_set_pool_vector(int p_index_y, const PoolRealArray &p_row);
|
||||
void row_set_mlpp_vector(int p_index_y, const Ref<MLPPVector> &p_row);
|
||||
|
||||
void fill(real_t p_val);
|
||||
void fill(real_t p_val);
|
||||
|
||||
Vector<real_t> to_flat_vector() const;
|
||||
PoolRealArray to_flat_pool_vector() const;
|
||||
Vector<uint8_t> to_flat_byte_array() const;
|
||||
Vector<real_t> to_flat_vector() const;
|
||||
PoolRealArray to_flat_pool_vector() const;
|
||||
Vector<uint8_t> to_flat_byte_array() const;
|
||||
|
||||
Ref<MLPPMatrix> duplicate_fast() const;
|
||||
Ref<MLPPMatrix> duplicate_fast() const;
|
||||
|
||||
void set_from_mlpp_matrix(const Ref<MLPPMatrix> &p_from);
|
||||
void set_from_mlpp_matrixr(const MLPPMatrix &p_from);
|
||||
void set_from_mlpp_vectors(const Vector<Ref<MLPPVector>> &p_from);
|
||||
void set_from_mlpp_vectors_array(const Array &p_from);
|
||||
void set_from_vectors(const Vector<Vector<real_t>> &p_from);
|
||||
void set_from_arrays(const Array &p_from);
|
||||
void set_from_ptr(const real_t *p_from, const int p_size_y, const int p_size_x);
|
||||
void set_from_mlpp_matrix(const Ref<MLPPMatrix> &p_from);
|
||||
void set_from_mlpp_matrixr(const MLPPMatrix &p_from);
|
||||
void set_from_mlpp_vectors(const Vector<Ref<MLPPVector>> &p_from);
|
||||
void set_from_mlpp_vectors_array(const Array &p_from);
|
||||
void set_from_vectors(const Vector<Vector<real_t>> &p_from);
|
||||
void set_from_arrays(const Array &p_from);
|
||||
void set_from_ptr(const real_t *p_from, const int p_size_y,
|
||||
const int p_size_x);
|
||||
|
||||
//std::vector<std::vector<real_t>> gramMatrix(std::vector<std::vector<real_t>> A);
|
||||
//bool linearIndependenceChecker(std::vector<std::vector<real_t>> A);
|
||||
// std::vector<std::vector<real_t>>
|
||||
// gramMatrix(std::vector<std::vector<real_t>> A); bool
|
||||
// linearIndependenceChecker(std::vector<std::vector<real_t>> A);
|
||||
|
||||
Ref<MLPPMatrix> gaussian_noise(int n, int m) const;
|
||||
void gaussian_noise_fill();
|
||||
Ref<MLPPMatrix> gaussian_noise(int n, int m) const;
|
||||
void gaussian_noise_fill();
|
||||
|
||||
static Ref<MLPPMatrix> create_gaussian_noise(int n, int m);
|
||||
static Ref<MLPPMatrix> create_gaussian_noise(int n, int m);
|
||||
|
||||
void add(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPMatrix> addn(const Ref<MLPPMatrix> &B) const;
|
||||
void addb(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B);
|
||||
void add(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPMatrix> addn(const Ref<MLPPMatrix> &B) const;
|
||||
void addb(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B);
|
||||
|
||||
void sub(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPMatrix> subn(const Ref<MLPPMatrix> &B) const;
|
||||
void subb(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B);
|
||||
void sub(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPMatrix> subn(const Ref<MLPPMatrix> &B) const;
|
||||
void subb(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B);
|
||||
|
||||
void mult(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPMatrix> multn(const Ref<MLPPMatrix> &B) const;
|
||||
void multb(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B);
|
||||
void mult(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPMatrix> multn(const Ref<MLPPMatrix> &B) const;
|
||||
void multb(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B);
|
||||
|
||||
void hadamard_product(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPMatrix> hadamard_productn(const Ref<MLPPMatrix> &B) const;
|
||||
void hadamard_productb(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B);
|
||||
void hadamard_product(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPMatrix> hadamard_productn(const Ref<MLPPMatrix> &B) const;
|
||||
void hadamard_productb(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B);
|
||||
|
||||
void kronecker_product(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPMatrix> kronecker_productn(const Ref<MLPPMatrix> &B) const;
|
||||
void kronecker_productb(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B);
|
||||
void kronecker_product(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPMatrix> kronecker_productn(const Ref<MLPPMatrix> &B) const;
|
||||
void kronecker_productb(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B);
|
||||
|
||||
void division_element_wise(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPMatrix> division_element_wisen(const Ref<MLPPMatrix> &B) const;
|
||||
void division_element_wiseb(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B);
|
||||
void division_element_wise(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPMatrix> division_element_wisen(const Ref<MLPPMatrix> &B) const;
|
||||
void division_element_wiseb(const Ref<MLPPMatrix> &A,
|
||||
const Ref<MLPPMatrix> &B);
|
||||
|
||||
void transpose();
|
||||
Ref<MLPPMatrix> transposen() const;
|
||||
void transposeb(const Ref<MLPPMatrix> &A);
|
||||
void transpose();
|
||||
Ref<MLPPMatrix> transposen() const;
|
||||
void transposeb(const Ref<MLPPMatrix> &A);
|
||||
|
||||
void scalar_multiply(const real_t scalar);
|
||||
Ref<MLPPMatrix> scalar_multiplyn(const real_t scalar) const;
|
||||
void scalar_multiplyb(const real_t scalar, const Ref<MLPPMatrix> &A);
|
||||
void scalar_multiply(const real_t scalar);
|
||||
Ref<MLPPMatrix> scalar_multiplyn(const real_t scalar) const;
|
||||
void scalar_multiplyb(const real_t scalar, const Ref<MLPPMatrix> &A);
|
||||
|
||||
void scalar_add(const real_t scalar);
|
||||
Ref<MLPPMatrix> scalar_addn(const real_t scalar) const;
|
||||
void scalar_addb(const real_t scalar, const Ref<MLPPMatrix> &A);
|
||||
void scalar_add(const real_t scalar);
|
||||
Ref<MLPPMatrix> scalar_addn(const real_t scalar) const;
|
||||
void scalar_addb(const real_t scalar, const Ref<MLPPMatrix> &A);
|
||||
|
||||
void log();
|
||||
Ref<MLPPMatrix> logn() const;
|
||||
void logb(const Ref<MLPPMatrix> &A);
|
||||
void log();
|
||||
Ref<MLPPMatrix> logn() const;
|
||||
void logb(const Ref<MLPPMatrix> &A);
|
||||
|
||||
void log10();
|
||||
Ref<MLPPMatrix> log10n() const;
|
||||
void log10b(const Ref<MLPPMatrix> &A);
|
||||
void log10();
|
||||
Ref<MLPPMatrix> log10n() const;
|
||||
void log10b(const Ref<MLPPMatrix> &A);
|
||||
|
||||
void exp();
|
||||
Ref<MLPPMatrix> expn() const;
|
||||
void expb(const Ref<MLPPMatrix> &A);
|
||||
void exp();
|
||||
Ref<MLPPMatrix> expn() const;
|
||||
void expb(const Ref<MLPPMatrix> &A);
|
||||
|
||||
void erf();
|
||||
Ref<MLPPMatrix> erfn() const;
|
||||
void erfb(const Ref<MLPPMatrix> &A);
|
||||
void erf();
|
||||
Ref<MLPPMatrix> erfn() const;
|
||||
void erfb(const Ref<MLPPMatrix> &A);
|
||||
|
||||
void exponentiate(real_t p);
|
||||
Ref<MLPPMatrix> exponentiaten(real_t p) const;
|
||||
void exponentiateb(const Ref<MLPPMatrix> &A, real_t p);
|
||||
void exponentiate(real_t p);
|
||||
Ref<MLPPMatrix> exponentiaten(real_t p) const;
|
||||
void exponentiateb(const Ref<MLPPMatrix> &A, real_t p);
|
||||
|
||||
void sqrt();
|
||||
Ref<MLPPMatrix> sqrtn() const;
|
||||
void sqrtb(const Ref<MLPPMatrix> &A);
|
||||
void sqrt();
|
||||
Ref<MLPPMatrix> sqrtn() const;
|
||||
void sqrtb(const Ref<MLPPMatrix> &A);
|
||||
|
||||
void cbrt();
|
||||
Ref<MLPPMatrix> cbrtn() const;
|
||||
void cbrtb(const Ref<MLPPMatrix> &A);
|
||||
void cbrt();
|
||||
Ref<MLPPMatrix> cbrtn() const;
|
||||
void cbrtb(const Ref<MLPPMatrix> &A);
|
||||
|
||||
Ref<MLPPMatrix> matrix_powern(const int n) const;
|
||||
Ref<MLPPMatrix> matrix_powern(const int n) const;
|
||||
|
||||
void abs();
|
||||
Ref<MLPPMatrix> absn() const;
|
||||
void absb(const Ref<MLPPMatrix> &A);
|
||||
void abs();
|
||||
Ref<MLPPMatrix> absn() const;
|
||||
void absb(const Ref<MLPPMatrix> &A);
|
||||
|
||||
real_t det(int d = -1) const;
|
||||
real_t detb(const Ref<MLPPMatrix> &A, int d) const;
|
||||
real_t det(int d = -1) const;
|
||||
real_t detb(const Ref<MLPPMatrix> &A, int d) const;
|
||||
|
||||
real_t trace() const;
|
||||
real_t trace() const;
|
||||
|
||||
Ref<MLPPMatrix> cofactor(int n, int i, int j) const;
|
||||
void cofactoro(int n, int i, int j, Ref<MLPPMatrix> out) const;
|
||||
Ref<MLPPMatrix> cofactor(int n, int i, int j) const;
|
||||
void cofactoro(int n, int i, int j, Ref<MLPPMatrix> out) const;
|
||||
|
||||
Ref<MLPPMatrix> adjoint() const;
|
||||
void adjointo(Ref<MLPPMatrix> out) const;
|
||||
Ref<MLPPMatrix> adjoint() const;
|
||||
void adjointo(Ref<MLPPMatrix> out) const;
|
||||
|
||||
Ref<MLPPMatrix> inverse() const;
|
||||
void inverseo(Ref<MLPPMatrix> out) const;
|
||||
Ref<MLPPMatrix> inverse() const;
|
||||
void inverseo(Ref<MLPPMatrix> out) const;
|
||||
|
||||
Ref<MLPPMatrix> pinverse() const;
|
||||
void pinverseo(Ref<MLPPMatrix> out) const;
|
||||
Ref<MLPPMatrix> pinverse() const;
|
||||
void pinverseo(Ref<MLPPMatrix> out) const;
|
||||
|
||||
Ref<MLPPMatrix> matn_zero(int n, int m) const;
|
||||
Ref<MLPPMatrix> matn_one(int n, int m) const;
|
||||
Ref<MLPPMatrix> matn_full(int n, int m, int k) const;
|
||||
Ref<MLPPMatrix> matn_zero(int n, int m) const;
|
||||
Ref<MLPPMatrix> matn_one(int n, int m) const;
|
||||
Ref<MLPPMatrix> matn_full(int n, int m, int k) const;
|
||||
|
||||
void sin();
|
||||
Ref<MLPPMatrix> sinn() const;
|
||||
void sinb(const Ref<MLPPMatrix> &A);
|
||||
void sin();
|
||||
Ref<MLPPMatrix> sinn() const;
|
||||
void sinb(const Ref<MLPPMatrix> &A);
|
||||
|
||||
void cos();
|
||||
Ref<MLPPMatrix> cosn() const;
|
||||
void cosb(const Ref<MLPPMatrix> &A);
|
||||
void cos();
|
||||
Ref<MLPPMatrix> cosn() const;
|
||||
void cosb(const Ref<MLPPMatrix> &A);
|
||||
|
||||
Ref<MLPPMatrix> create_rotation_matrix(real_t theta, int axis = -1);
|
||||
Ref<MLPPMatrix> create_rotation_matrix(real_t theta, int axis = -1);
|
||||
|
||||
void rotate(real_t theta, int axis = -1);
|
||||
Ref<MLPPMatrix> rotaten(real_t theta, int axis = -1);
|
||||
void rotateb(const Ref<MLPPMatrix> &A, real_t theta, int axis = -1);
|
||||
void rotate(real_t theta, int axis = -1);
|
||||
Ref<MLPPMatrix> rotaten(real_t theta, int axis = -1);
|
||||
void rotateb(const Ref<MLPPMatrix> &A, real_t theta, int axis = -1);
|
||||
|
||||
void max(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPMatrix> maxn(const Ref<MLPPMatrix> &B) const;
|
||||
void maxb(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B);
|
||||
void max(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPMatrix> maxn(const Ref<MLPPMatrix> &B) const;
|
||||
void maxb(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B);
|
||||
|
||||
void min(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPMatrix> minn(const Ref<MLPPMatrix> &B) const;
|
||||
void minb(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B);
|
||||
void min(const Ref<MLPPMatrix> &B);
|
||||
Ref<MLPPMatrix> minn(const Ref<MLPPMatrix> &B) const;
|
||||
void minb(const Ref<MLPPMatrix> &A, const Ref<MLPPMatrix> &B);
|
||||
|
||||
//real_t max(std::vector<std::vector<real_t>> A);
|
||||
//real_t min(std::vector<std::vector<real_t>> A);
|
||||
// real_t max(std::vector<std::vector<real_t>> A);
|
||||
// real_t min(std::vector<std::vector<real_t>> A);
|
||||
|
||||
//std::vector<std::vector<real_t>> round(std::vector<std::vector<real_t>> A);
|
||||
// std::vector<std::vector<real_t>> round(std::vector<std::vector<real_t>> A);
|
||||
|
||||
//real_t norm_2(std::vector<std::vector<real_t>> A);
|
||||
// real_t norm_2(std::vector<std::vector<real_t>> A);
|
||||
|
||||
void identity();
|
||||
Ref<MLPPMatrix> identityn() const;
|
||||
Ref<MLPPMatrix> identity_mat(int d) const;
|
||||
void identity();
|
||||
Ref<MLPPMatrix> identityn() const;
|
||||
Ref<MLPPMatrix> identity_mat(int d) const;
|
||||
|
||||
static Ref<MLPPMatrix> create_identity_mat(int d);
|
||||
static Ref<MLPPMatrix> create_identity_mat(int d);
|
||||
|
||||
Ref<MLPPMatrix> cov() const;
|
||||
void covo(Ref<MLPPMatrix> out) const;
|
||||
Ref<MLPPMatrix> cov() const;
|
||||
void covo(Ref<MLPPMatrix> out) const;
|
||||
|
||||
struct EigenResult {
|
||||
Ref<MLPPMatrix> eigen_vectors;
|
||||
Ref<MLPPMatrix> eigen_values;
|
||||
};
|
||||
struct EigenResult {
|
||||
Ref<MLPPMatrix> eigen_vectors;
|
||||
Ref<MLPPMatrix> eigen_values;
|
||||
};
|
||||
|
||||
EigenResult eigen() const;
|
||||
EigenResult eigenb(const Ref<MLPPMatrix> &A) const;
|
||||
Array eigen_bind();
|
||||
Array eigenb_bind(const Ref<MLPPMatrix> &A);
|
||||
EigenResult eigen() const;
|
||||
EigenResult eigenb(const Ref<MLPPMatrix> &A) const;
|
||||
Array eigen_bind();
|
||||
Array eigenb_bind(const Ref<MLPPMatrix> &A);
|
||||
|
||||
struct SVDResult {
|
||||
Ref<MLPPMatrix> U;
|
||||
Ref<MLPPMatrix> S;
|
||||
Ref<MLPPMatrix> Vt;
|
||||
};
|
||||
struct SVDResult {
|
||||
Ref<MLPPMatrix> U;
|
||||
Ref<MLPPMatrix> S;
|
||||
Ref<MLPPMatrix> Vt;
|
||||
};
|
||||
|
||||
SVDResult svd() const;
|
||||
SVDResult svdb(const Ref<MLPPMatrix> &A) const;
|
||||
Array svd_bind();
|
||||
Array svdb_bind(const Ref<MLPPMatrix> &A);
|
||||
SVDResult svd() const;
|
||||
SVDResult svdb(const Ref<MLPPMatrix> &A) const;
|
||||
Array svd_bind();
|
||||
Array svdb_bind(const Ref<MLPPMatrix> &A);
|
||||
|
||||
//std::vector<real_t> vectorProjection(std::vector<real_t> a, std::vector<real_t> b);
|
||||
// std::vector<real_t> vectorProjection(std::vector<real_t> a,
|
||||
// std::vector<real_t> b);
|
||||
|
||||
//std::vector<std::vector<real_t>> gramSchmidtProcess(std::vector<std::vector<real_t>> A);
|
||||
// std::vector<std::vector<real_t>>
|
||||
// gramSchmidtProcess(std::vector<std::vector<real_t>> A);
|
||||
|
||||
/*
|
||||
struct QRDResult {
|
||||
std::vector<std::vector<real_t>> Q;
|
||||
std::vector<std::vector<real_t>> R;
|
||||
};
|
||||
*/
|
||||
/*
|
||||
struct QRDResult {
|
||||
std::vector<std::vector<real_t>> Q;
|
||||
std::vector<std::vector<real_t>> R;
|
||||
};
|
||||
*/
|
||||
|
||||
//QRDResult qrd(std::vector<std::vector<real_t>> A);
|
||||
// QRDResult qrd(std::vector<std::vector<real_t>> A);
|
||||
|
||||
/*
|
||||
struct CholeskyResult {
|
||||
std::vector<std::vector<real_t>> L;
|
||||
std::vector<std::vector<real_t>> Lt;
|
||||
};
|
||||
/*
|
||||
struct CholeskyResult {
|
||||
std::vector<std::vector<real_t>> L;
|
||||
std::vector<std::vector<real_t>> Lt;
|
||||
};
|
||||
|
||||
CholeskyResult cholesky(std::vector<std::vector<real_t>> A);
|
||||
*/
|
||||
CholeskyResult cholesky(std::vector<std::vector<real_t>> A);
|
||||
*/
|
||||
|
||||
//real_t sum_elements(std::vector<std::vector<real_t>> A);
|
||||
// real_t sum_elements(std::vector<std::vector<real_t>> A);
|
||||
|
||||
Ref<MLPPVector> flatten() const;
|
||||
void flatteno(Ref<MLPPVector> out) const;
|
||||
Ref<MLPPVector> flatten() const;
|
||||
void flatteno(Ref<MLPPVector> out) const;
|
||||
|
||||
Ref<MLPPVector> solve(const Ref<MLPPVector> &b) const;
|
||||
Ref<MLPPVector> solve(const Ref<MLPPVector> &b) const;
|
||||
|
||||
/*
|
||||
bool positiveDefiniteChecker(std::vector<std::vector<real_t>> A);
|
||||
/*
|
||||
bool positiveDefiniteChecker(std::vector<std::vector<real_t>> A);
|
||||
|
||||
bool negativeDefiniteChecker(std::vector<std::vector<real_t>> A);
|
||||
bool negativeDefiniteChecker(std::vector<std::vector<real_t>> A);
|
||||
|
||||
bool zeroEigenvalue(std::vector<std::vector<real_t>> A);
|
||||
*/
|
||||
bool zeroEigenvalue(std::vector<std::vector<real_t>> A);
|
||||
*/
|
||||
|
||||
Ref<MLPPVector> mult_vec(const Ref<MLPPVector> &b) const;
|
||||
void mult_veco(const Ref<MLPPVector> &b, Ref<MLPPVector> out);
|
||||
Ref<MLPPVector> mult_vec(const Ref<MLPPVector> &b) const;
|
||||
void mult_veco(const Ref<MLPPVector> &b, Ref<MLPPVector> out);
|
||||
|
||||
void add_vec(const Ref<MLPPVector> &b);
|
||||
Ref<MLPPMatrix> add_vecn(const Ref<MLPPVector> &b) const;
|
||||
void add_vecb(const Ref<MLPPMatrix> &A, const Ref<MLPPVector> &b);
|
||||
void add_vec(const Ref<MLPPVector> &b);
|
||||
Ref<MLPPMatrix> add_vecn(const Ref<MLPPVector> &b) const;
|
||||
void add_vecb(const Ref<MLPPMatrix> &A, const Ref<MLPPVector> &b);
|
||||
|
||||
// This multiplies a, bT
|
||||
void outer_product(const Ref<MLPPVector> &a, const Ref<MLPPVector> &b);
|
||||
Ref<MLPPMatrix> outer_productn(const Ref<MLPPVector> &a, const Ref<MLPPVector> &b) const;
|
||||
// This multiplies a, bT
|
||||
void outer_product(const Ref<MLPPVector> &a, const Ref<MLPPVector> &b);
|
||||
Ref<MLPPMatrix> outer_productn(const Ref<MLPPVector> &a,
|
||||
const Ref<MLPPVector> &b) const;
|
||||
|
||||
// Just sets the diagonal
|
||||
void diagonal_set(const Ref<MLPPVector> &a);
|
||||
Ref<MLPPMatrix> diagonal_setn(const Ref<MLPPVector> &a) const;
|
||||
// Just sets the diagonal
|
||||
void diagonal_set(const Ref<MLPPVector> &a);
|
||||
Ref<MLPPMatrix> diagonal_setn(const Ref<MLPPVector> &a) const;
|
||||
|
||||
// Sets the diagonals, everythign else will get zeroed
|
||||
void diagonal_zeroed(const Ref<MLPPVector> &a);
|
||||
Ref<MLPPMatrix> diagonal_zeroedn(const Ref<MLPPVector> &a) const;
|
||||
// Sets the diagonals, everythign else will get zeroed
|
||||
void diagonal_zeroed(const Ref<MLPPVector> &a);
|
||||
Ref<MLPPMatrix> diagonal_zeroedn(const Ref<MLPPVector> &a) const;
|
||||
|
||||
bool is_equal_approx(const Ref<MLPPMatrix> &p_with, real_t tolerance = static_cast<real_t>(CMP_EPSILON)) const;
|
||||
bool
|
||||
is_equal_approx(const Ref<MLPPMatrix> &p_with,
|
||||
real_t tolerance = static_cast<real_t>(CMP_EPSILON)) const;
|
||||
|
||||
Ref<Image> get_as_image() const;
|
||||
void get_into_image(Ref<Image> out) const;
|
||||
void set_from_image(const Ref<Image> &p_img, const int p_image_channel);
|
||||
Ref<Image> get_as_image() const;
|
||||
void get_into_image(Ref<Image> out) const;
|
||||
void set_from_image(const Ref<Image> &p_img, const int p_image_channel);
|
||||
|
||||
String to_string();
|
||||
String to_string();
|
||||
|
||||
MLPPMatrix();
|
||||
MLPPMatrix(const MLPPMatrix &p_from);
|
||||
MLPPMatrix(const Vector<Vector<real_t>> &p_from);
|
||||
MLPPMatrix(const Array &p_from);
|
||||
MLPPMatrix(const real_t *p_from, const int p_size_y, const int p_size_x);
|
||||
MLPPMatrix();
|
||||
MLPPMatrix(const MLPPMatrix &p_from);
|
||||
MLPPMatrix(const Vector<Vector<real_t>> &p_from);
|
||||
MLPPMatrix(const Array &p_from);
|
||||
MLPPMatrix(const real_t *p_from, const int p_size_y, const int p_size_x);
|
||||
|
||||
~MLPPMatrix();
|
||||
~MLPPMatrix();
|
||||
|
||||
// TODO: These are temporary
|
||||
std::vector<real_t> to_flat_std_vector() const;
|
||||
void set_from_std_vectors(const std::vector<std::vector<real_t>> &p_from);
|
||||
std::vector<std::vector<real_t>> to_std_vector();
|
||||
void set_row_std_vector(int p_index_y, const std::vector<real_t> &p_row);
|
||||
MLPPMatrix(const std::vector<std::vector<real_t>> &p_from);
|
||||
// TODO: These are temporary
|
||||
std::vector<real_t> to_flat_std_vector() const;
|
||||
void set_from_std_vectors(const std::vector<std::vector<real_t>> &p_from);
|
||||
std::vector<std::vector<real_t>> to_std_vector();
|
||||
void set_row_std_vector(int p_index_y, const std::vector<real_t> &p_row);
|
||||
MLPPMatrix(const std::vector<std::vector<real_t>> &p_from);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
static void _bind_methods();
|
||||
|
||||
protected:
|
||||
Size2i _size;
|
||||
real_t *_data;
|
||||
Size2i _size;
|
||||
real_t *_data;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,5 @@
|
||||
#ifndef MLPP_TENSOR3_H
|
||||
#define MLPP_TENSOR3_H
|
||||
#ifndef GDNATIVE
|
||||
|
||||
/*************************************************************************/
|
||||
/* mlpp_tensor3.h */
|
||||
@ -32,6 +31,10 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/containers/pool_vector.h"
|
||||
@ -42,17 +45,6 @@
|
||||
#include "core/os/memory.h"
|
||||
|
||||
#include "core/object/resource.h"
|
||||
|
||||
#else
|
||||
|
||||
#include "core/containers/vector.h"
|
||||
#include "core/defs.h"
|
||||
#include "core/math_funcs.h"
|
||||
#include "core/os/memory.h"
|
||||
#include "core/pool_arrays.h"
|
||||
|
||||
#include "gen/resource.h"
|
||||
|
||||
#endif
|
||||
|
||||
#include "mlpp_matrix.h"
|
||||
@ -61,262 +53,301 @@
|
||||
class Image;
|
||||
|
||||
class MLPPTensor3 : public Resource {
|
||||
GDCLASS(MLPPTensor3, Resource);
|
||||
GDCLASS(MLPPTensor3, Resource);
|
||||
|
||||
public:
|
||||
Array get_data();
|
||||
void set_data(const Array &p_from);
|
||||
Array get_data();
|
||||
void set_data(const Array &p_from);
|
||||
|
||||
_FORCE_INLINE_ real_t *ptrw() {
|
||||
return _data;
|
||||
}
|
||||
_FORCE_INLINE_ real_t *ptrw() { return _data; }
|
||||
|
||||
_FORCE_INLINE_ const real_t *ptr() const {
|
||||
return _data;
|
||||
}
|
||||
_FORCE_INLINE_ const real_t *ptr() const { return _data; }
|
||||
|
||||
void z_slice_add(const Vector<real_t> &p_row);
|
||||
void z_slice_add_pool_vector(const PoolRealArray &p_row);
|
||||
void z_slice_add_mlpp_vector(const Ref<MLPPVector> &p_row);
|
||||
void z_slice_add_mlpp_matrix(const Ref<MLPPMatrix> &p_matrix);
|
||||
void z_slice_remove(int p_index);
|
||||
void z_slice_add(const Vector<real_t> &p_row);
|
||||
void z_slice_add_pool_vector(const PoolRealArray &p_row);
|
||||
void z_slice_add_mlpp_vector(const Ref<MLPPVector> &p_row);
|
||||
void z_slice_add_mlpp_matrix(const Ref<MLPPMatrix> &p_matrix);
|
||||
void z_slice_remove(int p_index);
|
||||
|
||||
// Removes the item copying the last value into the position of the one to
|
||||
// remove. It's generally faster than `remove`.
|
||||
void z_slice_remove_unordered(int p_index);
|
||||
// Removes the item copying the last value into the position of the one to
|
||||
// remove. It's generally faster than `remove`.
|
||||
void z_slice_remove_unordered(int p_index);
|
||||
|
||||
void z_slice_swap(int p_index_1, int p_index_2);
|
||||
void z_slice_swap(int p_index_1, int p_index_2);
|
||||
|
||||
_FORCE_INLINE_ void clear() { resize(Size3i()); }
|
||||
_FORCE_INLINE_ void reset() {
|
||||
if (_data) {
|
||||
memfree(_data);
|
||||
_data = NULL;
|
||||
_size = Size3i();
|
||||
}
|
||||
}
|
||||
_FORCE_INLINE_ void clear() { resize(Size3i()); }
|
||||
_FORCE_INLINE_ void reset() {
|
||||
if (_data) {
|
||||
memfree(_data);
|
||||
_data = NULL;
|
||||
_size = Size3i();
|
||||
}
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ bool empty() const { return _size == Size3i(); }
|
||||
_FORCE_INLINE_ int z_slice_data_size() const { return _size.x * _size.y; }
|
||||
_FORCE_INLINE_ Size2i z_slice_size() const { return Size2i(_size.x, _size.y); }
|
||||
_FORCE_INLINE_ int data_size() const { return _size.x * _size.y * _size.z; }
|
||||
_FORCE_INLINE_ Size3i size() const { return _size; }
|
||||
_FORCE_INLINE_ bool empty() const { return _size == Size3i(); }
|
||||
_FORCE_INLINE_ int z_slice_data_size() const { return _size.x * _size.y; }
|
||||
_FORCE_INLINE_ Size2i z_slice_size() const {
|
||||
return Size2i(_size.x, _size.y);
|
||||
}
|
||||
_FORCE_INLINE_ int data_size() const { return _size.x * _size.y * _size.z; }
|
||||
_FORCE_INLINE_ Size3i size() const { return _size; }
|
||||
|
||||
void resize(const Size3i &p_size);
|
||||
void shape_set(const Size3i &p_size);
|
||||
void resize(const Size3i &p_size);
|
||||
void shape_set(const Size3i &p_size);
|
||||
|
||||
_FORCE_INLINE_ int calculate_index(int p_index_z, int p_index_y, int p_index_x) const {
|
||||
return p_index_y * _size.x + p_index_x + _size.x * _size.y * p_index_z;
|
||||
}
|
||||
_FORCE_INLINE_ int calculate_index(int p_index_z, int p_index_y,
|
||||
int p_index_x) const {
|
||||
return p_index_y * _size.x + p_index_x + _size.x * _size.y * p_index_z;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ int calculate_z_slice_index(int p_index_z) const {
|
||||
return _size.x * _size.y * p_index_z;
|
||||
}
|
||||
_FORCE_INLINE_ int calculate_z_slice_index(int p_index_z) const {
|
||||
return _size.x * _size.y * p_index_z;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ const real_t &operator[](int p_index) const {
|
||||
CRASH_BAD_INDEX(p_index, data_size());
|
||||
return _data[p_index];
|
||||
}
|
||||
_FORCE_INLINE_ real_t &operator[](int p_index) {
|
||||
CRASH_BAD_INDEX(p_index, data_size());
|
||||
return _data[p_index];
|
||||
}
|
||||
_FORCE_INLINE_ const real_t &operator[](int p_index) const {
|
||||
CRASH_BAD_INDEX(p_index, data_size());
|
||||
return _data[p_index];
|
||||
}
|
||||
_FORCE_INLINE_ real_t &operator[](int p_index) {
|
||||
CRASH_BAD_INDEX(p_index, data_size());
|
||||
return _data[p_index];
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ real_t element_get_index(int p_index) const {
|
||||
ERR_FAIL_INDEX_V(p_index, data_size(), 0);
|
||||
_FORCE_INLINE_ real_t element_get_index(int p_index) const {
|
||||
ERR_FAIL_INDEX_V(p_index, data_size(), 0);
|
||||
|
||||
return _data[p_index];
|
||||
}
|
||||
return _data[p_index];
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void element_set_index(int p_index, real_t p_val) {
|
||||
ERR_FAIL_INDEX(p_index, data_size());
|
||||
_FORCE_INLINE_ void element_set_index(int p_index, real_t p_val) {
|
||||
ERR_FAIL_INDEX(p_index, data_size());
|
||||
|
||||
_data[p_index] = p_val;
|
||||
}
|
||||
_data[p_index] = p_val;
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ real_t element_get(int p_index_z, int p_index_y, int p_index_x) const {
|
||||
ERR_FAIL_INDEX_V(p_index_x, _size.x, 0);
|
||||
ERR_FAIL_INDEX_V(p_index_y, _size.y, 0);
|
||||
ERR_FAIL_INDEX_V(p_index_z, _size.z, 0);
|
||||
_FORCE_INLINE_ real_t element_get(int p_index_z, int p_index_y,
|
||||
int p_index_x) const {
|
||||
ERR_FAIL_INDEX_V(p_index_x, _size.x, 0);
|
||||
ERR_FAIL_INDEX_V(p_index_y, _size.y, 0);
|
||||
ERR_FAIL_INDEX_V(p_index_z, _size.z, 0);
|
||||
|
||||
return _data[p_index_y * _size.x + p_index_x + _size.x * _size.y * p_index_z];
|
||||
}
|
||||
return _data[p_index_y * _size.x + p_index_x +
|
||||
_size.x * _size.y * p_index_z];
|
||||
}
|
||||
|
||||
_FORCE_INLINE_ void element_set(int p_index_z, int p_index_y, int p_index_x, real_t p_val) {
|
||||
ERR_FAIL_INDEX(p_index_x, _size.x);
|
||||
ERR_FAIL_INDEX(p_index_y, _size.y);
|
||||
ERR_FAIL_INDEX(p_index_z, _size.z);
|
||||
_FORCE_INLINE_ void element_set(int p_index_z, int p_index_y, int p_index_x,
|
||||
real_t p_val) {
|
||||
ERR_FAIL_INDEX(p_index_x, _size.x);
|
||||
ERR_FAIL_INDEX(p_index_y, _size.y);
|
||||
ERR_FAIL_INDEX(p_index_z, _size.z);
|
||||
|
||||
_data[p_index_y * _size.x + p_index_x + _size.x * _size.y * p_index_z] = p_val;
|
||||
}
|
||||
_data[p_index_y * _size.x + p_index_x + _size.x * _size.y * p_index_z] =
|
||||
p_val;
|
||||
}
|
||||
|
||||
Vector<real_t> row_get_vector(int p_index_z, int p_index_y) const;
|
||||
PoolRealArray row_get_pool_vector(int p_index_z, int p_index_y) const;
|
||||
Ref<MLPPVector> row_get_mlpp_vector(int p_index_z, int p_index_y) const;
|
||||
void row_get_into_mlpp_vector(int p_index_z, int p_index_y, Ref<MLPPVector> target) const;
|
||||
Vector<real_t> row_get_vector(int p_index_z, int p_index_y) const;
|
||||
PoolRealArray row_get_pool_vector(int p_index_z, int p_index_y) const;
|
||||
Ref<MLPPVector> row_get_mlpp_vector(int p_index_z, int p_index_y) const;
|
||||
void row_get_into_mlpp_vector(int p_index_z, int p_index_y,
|
||||
Ref<MLPPVector> target) const;
|
||||
|
||||
void row_set_vector(int p_index_z, int p_index_y, const Vector<real_t> &p_row);
|
||||
void row_set_pool_vector(int p_index_z, int p_index_y, const PoolRealArray &p_row);
|
||||
void row_set_mlpp_vector(int p_index_z, int p_index_y, const Ref<MLPPVector> &p_row);
|
||||
void row_set_vector(int p_index_z, int p_index_y,
|
||||
const Vector<real_t> &p_row);
|
||||
void row_set_pool_vector(int p_index_z, int p_index_y,
|
||||
const PoolRealArray &p_row);
|
||||
void row_set_mlpp_vector(int p_index_z, int p_index_y,
|
||||
const Ref<MLPPVector> &p_row);
|
||||
|
||||
Vector<real_t> z_slice_get_vector(int p_index_z) const;
|
||||
PoolRealArray z_slice_get_pool_vector(int p_index_z) const;
|
||||
Ref<MLPPVector> z_slice_get_mlpp_vector(int p_index_z) const;
|
||||
void z_slice_get_into_mlpp_vector(int p_index_z, Ref<MLPPVector> target) const;
|
||||
Ref<MLPPMatrix> z_slice_get_mlpp_matrix(int p_index_z) const;
|
||||
void z_slice_get_into_mlpp_matrix(int p_index_z, Ref<MLPPMatrix> target) const;
|
||||
Vector<real_t> z_slice_get_vector(int p_index_z) const;
|
||||
PoolRealArray z_slice_get_pool_vector(int p_index_z) const;
|
||||
Ref<MLPPVector> z_slice_get_mlpp_vector(int p_index_z) const;
|
||||
void z_slice_get_into_mlpp_vector(int p_index_z,
|
||||
Ref<MLPPVector> target) const;
|
||||
Ref<MLPPMatrix> z_slice_get_mlpp_matrix(int p_index_z) const;
|
||||
void z_slice_get_into_mlpp_matrix(int p_index_z,
|
||||
Ref<MLPPMatrix> target) const;
|
||||
|
||||
void z_slice_set_vector(int p_index_z, const Vector<real_t> &p_row);
|
||||
void z_slice_set_pool_vector(int p_index_z, const PoolRealArray &p_row);
|
||||
void z_slice_set_mlpp_vector(int p_index_z, const Ref<MLPPVector> &p_row);
|
||||
void z_slice_set_mlpp_matrix(int p_index_z, const Ref<MLPPMatrix> &p_mat);
|
||||
void z_slice_set_vector(int p_index_z, const Vector<real_t> &p_row);
|
||||
void z_slice_set_pool_vector(int p_index_z, const PoolRealArray &p_row);
|
||||
void z_slice_set_mlpp_vector(int p_index_z, const Ref<MLPPVector> &p_row);
|
||||
void z_slice_set_mlpp_matrix(int p_index_z, const Ref<MLPPMatrix> &p_mat);
|
||||
|
||||
//TODO resize() need to be reworked for add and remove to work, in any other direction than z
|
||||
//void x_slice_add(const Ref<MLPPMatrix> &p_matrix);
|
||||
//void x_slice_remove(int p_index);
|
||||
void x_slice_get_into(int p_index_x, Ref<MLPPMatrix> target) const;
|
||||
Ref<MLPPMatrix> x_slice_get(int p_index_x) const;
|
||||
void x_slice_set(int p_index_x, const Ref<MLPPMatrix> &p_mat);
|
||||
// TODO resize() need to be reworked for add and remove to work, in any other
|
||||
// direction than z void x_slice_add(const Ref<MLPPMatrix> &p_matrix); void
|
||||
// x_slice_remove(int p_index);
|
||||
void x_slice_get_into(int p_index_x, Ref<MLPPMatrix> target) const;
|
||||
Ref<MLPPMatrix> x_slice_get(int p_index_x) const;
|
||||
void x_slice_set(int p_index_x, const Ref<MLPPMatrix> &p_mat);
|
||||
|
||||
//void y_slice_add(const Ref<MLPPMatrix> &p_matrix);
|
||||
//void y_slice_remove(int p_index);
|
||||
void y_slice_get_into(int p_index_y, Ref<MLPPMatrix> target) const;
|
||||
Ref<MLPPMatrix> y_slice_get(int p_index_y) const;
|
||||
void y_slice_set(int p_index_y, const Ref<MLPPMatrix> &p_mat);
|
||||
// void y_slice_add(const Ref<MLPPMatrix> &p_matrix);
|
||||
// void y_slice_remove(int p_index);
|
||||
void y_slice_get_into(int p_index_y, Ref<MLPPMatrix> target) const;
|
||||
Ref<MLPPMatrix> y_slice_get(int p_index_y) const;
|
||||
void y_slice_set(int p_index_y, const Ref<MLPPMatrix> &p_mat);
|
||||
|
||||
public:
|
||||
//Image api
|
||||
// Image api
|
||||
|
||||
enum ImageChannelFlags {
|
||||
IMAGE_CHANNEL_FLAG_R = 1 << 0,
|
||||
IMAGE_CHANNEL_FLAG_G = 1 << 1,
|
||||
IMAGE_CHANNEL_FLAG_B = 1 << 2,
|
||||
IMAGE_CHANNEL_FLAG_A = 1 << 3,
|
||||
enum ImageChannelFlags {
|
||||
IMAGE_CHANNEL_FLAG_R = 1 << 0,
|
||||
IMAGE_CHANNEL_FLAG_G = 1 << 1,
|
||||
IMAGE_CHANNEL_FLAG_B = 1 << 2,
|
||||
IMAGE_CHANNEL_FLAG_A = 1 << 3,
|
||||
|
||||
IMAGE_CHANNEL_FLAG_NONE = 0,
|
||||
IMAGE_CHANNEL_FLAG_RG = IMAGE_CHANNEL_FLAG_R | IMAGE_CHANNEL_FLAG_G,
|
||||
IMAGE_CHANNEL_FLAG_RGB = IMAGE_CHANNEL_FLAG_R | IMAGE_CHANNEL_FLAG_G | IMAGE_CHANNEL_FLAG_B,
|
||||
IMAGE_CHANNEL_FLAG_GB = IMAGE_CHANNEL_FLAG_G | IMAGE_CHANNEL_FLAG_B,
|
||||
IMAGE_CHANNEL_FLAG_GBA = IMAGE_CHANNEL_FLAG_G | IMAGE_CHANNEL_FLAG_B | IMAGE_CHANNEL_FLAG_A,
|
||||
IMAGE_CHANNEL_FLAG_BA = IMAGE_CHANNEL_FLAG_B | IMAGE_CHANNEL_FLAG_A,
|
||||
IMAGE_CHANNEL_FLAG_RGBA = IMAGE_CHANNEL_FLAG_R | IMAGE_CHANNEL_FLAG_G | IMAGE_CHANNEL_FLAG_B | IMAGE_CHANNEL_FLAG_A,
|
||||
};
|
||||
IMAGE_CHANNEL_FLAG_NONE = 0,
|
||||
IMAGE_CHANNEL_FLAG_RG = IMAGE_CHANNEL_FLAG_R | IMAGE_CHANNEL_FLAG_G,
|
||||
IMAGE_CHANNEL_FLAG_RGB =
|
||||
IMAGE_CHANNEL_FLAG_R | IMAGE_CHANNEL_FLAG_G | IMAGE_CHANNEL_FLAG_B,
|
||||
IMAGE_CHANNEL_FLAG_GB = IMAGE_CHANNEL_FLAG_G | IMAGE_CHANNEL_FLAG_B,
|
||||
IMAGE_CHANNEL_FLAG_GBA =
|
||||
IMAGE_CHANNEL_FLAG_G | IMAGE_CHANNEL_FLAG_B | IMAGE_CHANNEL_FLAG_A,
|
||||
IMAGE_CHANNEL_FLAG_BA = IMAGE_CHANNEL_FLAG_B | IMAGE_CHANNEL_FLAG_A,
|
||||
IMAGE_CHANNEL_FLAG_RGBA = IMAGE_CHANNEL_FLAG_R | IMAGE_CHANNEL_FLAG_G |
|
||||
IMAGE_CHANNEL_FLAG_B | IMAGE_CHANNEL_FLAG_A,
|
||||
};
|
||||
|
||||
void z_slices_add_image(const Ref<Image> &p_img, const int p_channels = IMAGE_CHANNEL_FLAG_RGBA);
|
||||
void z_slices_add_image(const Ref<Image> &p_img,
|
||||
const int p_channels = IMAGE_CHANNEL_FLAG_RGBA);
|
||||
|
||||
Ref<Image> z_slice_get_image(const int p_index_z) const;
|
||||
Ref<Image> z_slices_get_image(const int p_index_r = -1, const int p_index_g = -1, const int p_index_b = -1, const int p_index_a = -1) const;
|
||||
Ref<Image> z_slice_get_image(const int p_index_z) const;
|
||||
Ref<Image> z_slices_get_image(const int p_index_r = -1,
|
||||
const int p_index_g = -1,
|
||||
const int p_index_b = -1,
|
||||
const int p_index_a = -1) const;
|
||||
|
||||
void z_slice_get_into_image(Ref<Image> p_target, const int p_index_z, const int p_target_channels = IMAGE_CHANNEL_FLAG_RGB) const;
|
||||
void z_slices_get_into_image(Ref<Image> p_target, const int p_index_r = -1, const int p_index_g = -1, const int p_index_b = -1, const int p_index_a = -1) const;
|
||||
void z_slice_get_into_image(
|
||||
Ref<Image> p_target, const int p_index_z,
|
||||
const int p_target_channels = IMAGE_CHANNEL_FLAG_RGB) const;
|
||||
void z_slices_get_into_image(Ref<Image> p_target, const int p_index_r = -1,
|
||||
const int p_index_g = -1,
|
||||
const int p_index_b = -1,
|
||||
const int p_index_a = -1) const;
|
||||
|
||||
void z_slice_set_image(const Ref<Image> &p_img, const int p_index_z, const int p_image_channel_flag = IMAGE_CHANNEL_FLAG_R);
|
||||
void z_slices_set_image(const Ref<Image> &p_img, const int p_index_r = -1, const int p_index_g = -1, const int p_index_b = -1, const int p_index_a = -1);
|
||||
void z_slice_set_image(const Ref<Image> &p_img, const int p_index_z,
|
||||
const int p_image_channel_flag = IMAGE_CHANNEL_FLAG_R);
|
||||
void z_slices_set_image(const Ref<Image> &p_img, const int p_index_r = -1,
|
||||
const int p_index_g = -1, const int p_index_b = -1,
|
||||
const int p_index_a = -1);
|
||||
|
||||
void set_from_image(const Ref<Image> &p_img, const int p_channels = IMAGE_CHANNEL_FLAG_RGBA);
|
||||
void set_from_image(const Ref<Image> &p_img,
|
||||
const int p_channels = IMAGE_CHANNEL_FLAG_RGBA);
|
||||
|
||||
//void x_slices_add_image(const Ref<Image> &p_img, const int p_channels = IMAGE_CHANNEL_FLAG_RGBA);
|
||||
Ref<Image> x_slice_get_image(const int p_index_x) const;
|
||||
void x_slice_get_into_image(Ref<Image> p_target, const int p_index_x, const int p_target_channels = IMAGE_CHANNEL_FLAG_RGB) const;
|
||||
void x_slice_set_image(const Ref<Image> &p_img, const int p_index_x, const int p_image_channel_flag = IMAGE_CHANNEL_FLAG_R);
|
||||
// void x_slices_add_image(const Ref<Image> &p_img, const int p_channels =
|
||||
// IMAGE_CHANNEL_FLAG_RGBA);
|
||||
Ref<Image> x_slice_get_image(const int p_index_x) const;
|
||||
void x_slice_get_into_image(
|
||||
Ref<Image> p_target, const int p_index_x,
|
||||
const int p_target_channels = IMAGE_CHANNEL_FLAG_RGB) const;
|
||||
void x_slice_set_image(const Ref<Image> &p_img, const int p_index_x,
|
||||
const int p_image_channel_flag = IMAGE_CHANNEL_FLAG_R);
|
||||
|
||||
//void y_slices_add_image(const Ref<Image> &p_img, const int p_channels = IMAGE_CHANNEL_FLAG_RGBA);
|
||||
Ref<Image> y_slice_get_image(const int p_index_y) const;
|
||||
void y_slice_get_into_image(Ref<Image> p_target, const int p_index_y, const int p_target_channels = IMAGE_CHANNEL_FLAG_RGB) const;
|
||||
void y_slice_set_image(const Ref<Image> &p_img, const int p_index_y, const int p_image_channel_flag = IMAGE_CHANNEL_FLAG_R);
|
||||
// void y_slices_add_image(const Ref<Image> &p_img, const int p_channels =
|
||||
// IMAGE_CHANNEL_FLAG_RGBA);
|
||||
Ref<Image> y_slice_get_image(const int p_index_y) const;
|
||||
void y_slice_get_into_image(
|
||||
Ref<Image> p_target, const int p_index_y,
|
||||
const int p_target_channels = IMAGE_CHANNEL_FLAG_RGB) const;
|
||||
void y_slice_set_image(const Ref<Image> &p_img, const int p_index_y,
|
||||
const int p_image_channel_flag = IMAGE_CHANNEL_FLAG_R);
|
||||
|
||||
public:
|
||||
//math api
|
||||
// math api
|
||||
|
||||
void add(const Ref<MLPPTensor3> &B);
|
||||
Ref<MLPPTensor3> addn(const Ref<MLPPTensor3> &B) const;
|
||||
void addb(const Ref<MLPPTensor3> &A, const Ref<MLPPTensor3> &B);
|
||||
void add(const Ref<MLPPTensor3> &B);
|
||||
Ref<MLPPTensor3> addn(const Ref<MLPPTensor3> &B) const;
|
||||
void addb(const Ref<MLPPTensor3> &A, const Ref<MLPPTensor3> &B);
|
||||
|
||||
void sub(const Ref<MLPPTensor3> &B);
|
||||
Ref<MLPPTensor3> subn(const Ref<MLPPTensor3> &B) const;
|
||||
void subb(const Ref<MLPPTensor3> &A, const Ref<MLPPTensor3> &B);
|
||||
void sub(const Ref<MLPPTensor3> &B);
|
||||
Ref<MLPPTensor3> subn(const Ref<MLPPTensor3> &B) const;
|
||||
void subb(const Ref<MLPPTensor3> &A, const Ref<MLPPTensor3> &B);
|
||||
|
||||
void division_element_wise(const Ref<MLPPTensor3> &B);
|
||||
Ref<MLPPTensor3> division_element_wisen(const Ref<MLPPTensor3> &B) const;
|
||||
void division_element_wiseb(const Ref<MLPPTensor3> &A, const Ref<MLPPTensor3> &B);
|
||||
void division_element_wise(const Ref<MLPPTensor3> &B);
|
||||
Ref<MLPPTensor3> division_element_wisen(const Ref<MLPPTensor3> &B) const;
|
||||
void division_element_wiseb(const Ref<MLPPTensor3> &A,
|
||||
const Ref<MLPPTensor3> &B);
|
||||
|
||||
void sqrt();
|
||||
Ref<MLPPTensor3> sqrtn() const;
|
||||
void sqrtb(const Ref<MLPPTensor3> &A);
|
||||
void sqrt();
|
||||
Ref<MLPPTensor3> sqrtn() const;
|
||||
void sqrtb(const Ref<MLPPTensor3> &A);
|
||||
|
||||
void exponentiate(real_t p);
|
||||
Ref<MLPPTensor3> exponentiaten(real_t p) const;
|
||||
void exponentiateb(const Ref<MLPPTensor3> &A, real_t p);
|
||||
void exponentiate(real_t p);
|
||||
Ref<MLPPTensor3> exponentiaten(real_t p) const;
|
||||
void exponentiateb(const Ref<MLPPTensor3> &A, real_t p);
|
||||
|
||||
void scalar_multiply(const real_t scalar);
|
||||
Ref<MLPPTensor3> scalar_multiplyn(const real_t scalar) const;
|
||||
void scalar_multiplyb(const real_t scalar, const Ref<MLPPTensor3> &A);
|
||||
void scalar_multiply(const real_t scalar);
|
||||
Ref<MLPPTensor3> scalar_multiplyn(const real_t scalar) const;
|
||||
void scalar_multiplyb(const real_t scalar, const Ref<MLPPTensor3> &A);
|
||||
|
||||
void scalar_add(const real_t scalar);
|
||||
Ref<MLPPTensor3> scalar_addn(const real_t scalar) const;
|
||||
void scalar_addb(const real_t scalar, const Ref<MLPPTensor3> &A);
|
||||
void scalar_add(const real_t scalar);
|
||||
Ref<MLPPTensor3> scalar_addn(const real_t scalar) const;
|
||||
void scalar_addb(const real_t scalar, const Ref<MLPPTensor3> &A);
|
||||
|
||||
void hadamard_product(const Ref<MLPPTensor3> &B);
|
||||
Ref<MLPPTensor3> hadamard_productn(const Ref<MLPPTensor3> &B) const;
|
||||
void hadamard_productb(const Ref<MLPPTensor3> &A, const Ref<MLPPTensor3> &B);
|
||||
void hadamard_product(const Ref<MLPPTensor3> &B);
|
||||
Ref<MLPPTensor3> hadamard_productn(const Ref<MLPPTensor3> &B) const;
|
||||
void hadamard_productb(const Ref<MLPPTensor3> &A, const Ref<MLPPTensor3> &B);
|
||||
|
||||
void max(const Ref<MLPPTensor3> &B);
|
||||
Ref<MLPPTensor3> maxn(const Ref<MLPPTensor3> &B) const;
|
||||
void maxb(const Ref<MLPPTensor3> &A, const Ref<MLPPTensor3> &B);
|
||||
void max(const Ref<MLPPTensor3> &B);
|
||||
Ref<MLPPTensor3> maxn(const Ref<MLPPTensor3> &B) const;
|
||||
void maxb(const Ref<MLPPTensor3> &A, const Ref<MLPPTensor3> &B);
|
||||
|
||||
void abs();
|
||||
Ref<MLPPTensor3> absn() const;
|
||||
void absb(const Ref<MLPPTensor3> &A);
|
||||
void abs();
|
||||
Ref<MLPPTensor3> absn() const;
|
||||
void absb(const Ref<MLPPTensor3> &A);
|
||||
|
||||
Ref<MLPPVector> flatten() const;
|
||||
void flatteno(Ref<MLPPVector> out) const;
|
||||
Ref<MLPPVector> flatten() const;
|
||||
void flatteno(Ref<MLPPVector> out) const;
|
||||
|
||||
//real_t norm_2(std::vector<std::vector<std::vector<real_t>>> A);
|
||||
// real_t norm_2(std::vector<std::vector<std::vector<real_t>>> A);
|
||||
|
||||
Ref<MLPPMatrix> tensor_vec_mult(const Ref<MLPPVector> &b);
|
||||
//std::vector<std::vector<std::vector<real_t>>> vector_wise_tensor_product(std::vector<std::vector<std::vector<real_t>>> A, std::vector<std::vector<real_t>> B);
|
||||
Ref<MLPPMatrix> tensor_vec_mult(const Ref<MLPPVector> &b);
|
||||
// std::vector<std::vector<std::vector<real_t>>>
|
||||
// vector_wise_tensor_product(std::vector<std::vector<std::vector<real_t>>> A,
|
||||
// std::vector<std::vector<real_t>> B);
|
||||
|
||||
public:
|
||||
void fill(real_t p_val);
|
||||
void fill(real_t p_val);
|
||||
|
||||
Vector<real_t> to_flat_vector() const;
|
||||
PoolRealArray to_flat_pool_vector() const;
|
||||
Vector<uint8_t> to_flat_byte_array() const;
|
||||
Vector<real_t> to_flat_vector() const;
|
||||
PoolRealArray to_flat_pool_vector() const;
|
||||
Vector<uint8_t> to_flat_byte_array() const;
|
||||
|
||||
Ref<MLPPTensor3> duplicate_fast() const;
|
||||
Ref<MLPPTensor3> duplicate_fast() const;
|
||||
|
||||
void set_from_mlpp_tensor3(const Ref<MLPPTensor3> &p_from);
|
||||
void set_from_mlpp_tensor3r(const MLPPTensor3 &p_from);
|
||||
void set_from_mlpp_tensor3(const Ref<MLPPTensor3> &p_from);
|
||||
void set_from_mlpp_tensor3r(const MLPPTensor3 &p_from);
|
||||
|
||||
void set_from_mlpp_matrix(const Ref<MLPPMatrix> &p_from);
|
||||
void set_from_mlpp_matrixr(const MLPPMatrix &p_from);
|
||||
void set_from_mlpp_vectors(const Vector<Ref<MLPPVector>> &p_from);
|
||||
void set_from_mlpp_matricess(const Vector<Ref<MLPPMatrix>> &p_from);
|
||||
void set_from_mlpp_matrix(const Ref<MLPPMatrix> &p_from);
|
||||
void set_from_mlpp_matrixr(const MLPPMatrix &p_from);
|
||||
void set_from_mlpp_vectors(const Vector<Ref<MLPPVector>> &p_from);
|
||||
void set_from_mlpp_matricess(const Vector<Ref<MLPPMatrix>> &p_from);
|
||||
|
||||
void set_from_mlpp_vectors_array(const Array &p_from);
|
||||
void set_from_mlpp_matrices_array(const Array &p_from);
|
||||
void set_from_mlpp_vectors_array(const Array &p_from);
|
||||
void set_from_mlpp_matrices_array(const Array &p_from);
|
||||
|
||||
bool is_equal_approx(const Ref<MLPPTensor3> &p_with, real_t tolerance = static_cast<real_t>(CMP_EPSILON)) const;
|
||||
bool
|
||||
is_equal_approx(const Ref<MLPPTensor3> &p_with,
|
||||
real_t tolerance = static_cast<real_t>(CMP_EPSILON)) const;
|
||||
|
||||
String to_string();
|
||||
String to_string();
|
||||
|
||||
MLPPTensor3();
|
||||
MLPPTensor3(const MLPPMatrix &p_from);
|
||||
MLPPTensor3(const Array &p_from);
|
||||
~MLPPTensor3();
|
||||
MLPPTensor3();
|
||||
MLPPTensor3(const MLPPMatrix &p_from);
|
||||
MLPPTensor3(const Array &p_from);
|
||||
~MLPPTensor3();
|
||||
|
||||
// TODO: These are temporary
|
||||
std::vector<real_t> to_flat_std_vector() const;
|
||||
void set_from_std_vectors(const std::vector<std::vector<std::vector<real_t>>> &p_from);
|
||||
std::vector<std::vector<std::vector<real_t>>> to_std_vector();
|
||||
MLPPTensor3(const std::vector<std::vector<std::vector<real_t>>> &p_from);
|
||||
// TODO: These are temporary
|
||||
std::vector<real_t> to_flat_std_vector() const;
|
||||
void set_from_std_vectors(
|
||||
const std::vector<std::vector<std::vector<real_t>>> &p_from);
|
||||
std::vector<std::vector<std::vector<real_t>>> to_std_vector();
|
||||
MLPPTensor3(const std::vector<std::vector<std::vector<real_t>>> &p_from);
|
||||
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
static void _bind_methods();
|
||||
|
||||
protected:
|
||||
Size3i _size;
|
||||
real_t *_data;
|
||||
Size3i _size;
|
||||
real_t *_data;
|
||||
};
|
||||
|
||||
VARIANT_ENUM_CAST(MLPPTensor3::ImageChannelFlags);
|
||||
|
@ -1,6 +1,5 @@
|
||||
#ifndef MLPP_VECTOR_H
|
||||
#define MLPP_VECTOR_H
|
||||
#ifndef GDNATIVE
|
||||
|
||||
/*************************************************************************/
|
||||
/* mlpp_vector.h */
|
||||
@ -32,6 +31,9 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
#include "core/math/math_funcs.h"
|
||||
|
||||
@ -43,16 +45,6 @@
|
||||
|
||||
#include "core/object/resource.h"
|
||||
|
||||
#else
|
||||
|
||||
#include "core/containers/vector.h"
|
||||
#include "core/defs.h"
|
||||
#include "core/math_funcs.h"
|
||||
#include "core/os/memory.h"
|
||||
#include "core/pool_arrays.h"
|
||||
|
||||
#include "gen/resource.h"
|
||||
|
||||
#endif
|
||||
|
||||
//REMOVE
|
||||
|
@ -31,9 +31,13 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
|
@ -31,9 +31,13 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
|
@ -30,7 +30,11 @@
|
||||
|
||||
#include "mann.h"
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/log/logger.h"
|
||||
#endif
|
||||
|
||||
#include "../activation/activation.h"
|
||||
#include "../cost/cost.h"
|
||||
|
@ -31,9 +31,13 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../regularization/reg.h"
|
||||
|
||||
|
@ -30,7 +30,11 @@
|
||||
|
||||
#include "mlp.h"
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/log/logger.h"
|
||||
#endif
|
||||
|
||||
#include "../activation/activation.h"
|
||||
#include "../cost/cost.h"
|
||||
|
@ -31,12 +31,16 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/containers/vector.h"
|
||||
#include "core/math/math_defs.h"
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/variant/variant.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../regularization/reg.h"
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
/*************************************************************************/
|
||||
|
||||
#include "multi_output_layer.h"
|
||||
|
||||
#include "../utilities/utilities.h"
|
||||
|
||||
int MLPPMultiOutputLayer::get_n_output() {
|
||||
|
@ -31,10 +31,14 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
#include "core/string/ustring.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../activation/activation.h"
|
||||
#include "../cost/cost.h"
|
||||
|
@ -30,7 +30,11 @@
|
||||
|
||||
#include "multinomial_nb.h"
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/containers/local_vector.h"
|
||||
#endif
|
||||
|
||||
#include "../utilities/utilities.h"
|
||||
|
||||
|
@ -31,11 +31,15 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/containers/hash_map.h"
|
||||
#include "core/containers/vector.h"
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
|
@ -29,6 +29,7 @@
|
||||
/*************************************************************************/
|
||||
|
||||
#include "numerical_analysis.h"
|
||||
|
||||
#include "../lin_alg/lin_alg.h"
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
|
@ -36,12 +36,16 @@
|
||||
//
|
||||
//
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
|
||||
#include "core/containers/vector.h"
|
||||
#include "core/string/ustring.h"
|
||||
#endif
|
||||
|
||||
class MLPPVector;
|
||||
class MLPPMatrix;
|
||||
|
@ -31,9 +31,13 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
|
@ -29,6 +29,7 @@
|
||||
/*************************************************************************/
|
||||
|
||||
#include "output_layer.h"
|
||||
|
||||
#include "../utilities/utilities.h"
|
||||
|
||||
int MLPPOutputLayer::get_n_hidden() {
|
||||
|
@ -31,10 +31,14 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
#include "core/string/ustring.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../activation/activation.h"
|
||||
#include "../cost/cost.h"
|
||||
|
@ -29,6 +29,7 @@
|
||||
/*************************************************************************/
|
||||
|
||||
#include "pca.h"
|
||||
|
||||
#include "../data/data.h"
|
||||
|
||||
Ref<MLPPMatrix> MLPPPCA::get_input_set() {
|
||||
|
@ -31,9 +31,13 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
|
@ -31,9 +31,13 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/resource.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
|
@ -30,7 +30,11 @@
|
||||
|
||||
#include "reg.h"
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
#endif
|
||||
|
||||
#include "../activation/activation.h"
|
||||
#include "../lin_alg/lin_alg.h"
|
||||
|
@ -31,9 +31,13 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
|
@ -36,7 +36,11 @@
|
||||
#include "../regularization/reg.h"
|
||||
#include "../utilities/utilities.h"
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/log/logger.h"
|
||||
#endif
|
||||
|
||||
#include <random>
|
||||
|
||||
|
@ -31,9 +31,13 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/resource.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
|
@ -31,9 +31,13 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/resource.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
|
@ -29,10 +29,16 @@
|
||||
/*************************************************************************/
|
||||
|
||||
#include "stat.h"
|
||||
|
||||
#include "../activation/activation.h"
|
||||
#include "../data/data.h"
|
||||
#include "../lin_alg/lin_alg.h"
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/containers/hash_map.h"
|
||||
#endif
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
|
@ -31,9 +31,13 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
|
@ -34,9 +34,13 @@
|
||||
// https://towardsdatascience.com/svm-implementation-from-scratch-python-2db2fc52e5c2
|
||||
// Illustratd a practical definition of the Hinge Loss function and its gradient when optimizing with SGD.
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/resource.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
|
@ -31,9 +31,13 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/resource.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
|
@ -30,7 +30,11 @@
|
||||
|
||||
#include "mlpp_matrix_tests.h"
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/log/logger.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
|
||||
|
@ -31,6 +31,9 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/containers/vector.h"
|
||||
@ -38,6 +41,7 @@
|
||||
#include "core/object/reference.h"
|
||||
|
||||
#include "core/string/ustring.h"
|
||||
#endif
|
||||
|
||||
#include "mlpp_tests.h"
|
||||
|
||||
|
@ -30,9 +30,13 @@
|
||||
|
||||
#include "mlpp_tests.h"
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_funcs.h"
|
||||
|
||||
#include "core/log/logger.h"
|
||||
#endif
|
||||
|
||||
//TODO remove
|
||||
#include <cmath>
|
||||
|
@ -31,6 +31,9 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/containers/vector.h"
|
||||
@ -38,6 +41,7 @@
|
||||
#include "core/object/reference.h"
|
||||
|
||||
#include "core/string/ustring.h"
|
||||
#endif
|
||||
|
||||
// TODO port this class to use the test module once it's working
|
||||
// Also don't forget to remove it's bindings
|
||||
|
@ -29,9 +29,14 @@
|
||||
/*************************************************************************/
|
||||
|
||||
#include "transforms.h"
|
||||
|
||||
#include "../lin_alg/lin_alg.h"
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_funcs.h"
|
||||
#endif
|
||||
|
||||
// DCT ii.
|
||||
// https://www.mathworks.com/help/images/discrete-cosine-transform.html
|
||||
|
@ -36,9 +36,13 @@
|
||||
//
|
||||
//
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
|
||||
|
@ -31,9 +31,13 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/math/math_defs.h"
|
||||
|
||||
#include "core/object/resource.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
|
@ -30,9 +30,13 @@
|
||||
|
||||
#include "utilities.h"
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/log/logger.h"
|
||||
#include "core/math/math_funcs.h"
|
||||
#include "core/math/random_pcg.h"
|
||||
#endif
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
@ -31,12 +31,16 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/containers/vector.h"
|
||||
#include "core/math/math_defs.h"
|
||||
#include "core/string/ustring.h"
|
||||
#include "core/variant/variant.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_vector.h"
|
||||
|
686
wgan/wgan.cpp
686
wgan/wgan.cpp
@ -30,451 +30,555 @@
|
||||
|
||||
#include "wgan.h"
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/log/logger.h"
|
||||
|
||||
#include "core/object/method_bind_ext.gen.inc"
|
||||
#endif
|
||||
|
||||
#include "../activation/activation.h"
|
||||
#include "../cost/cost.h"
|
||||
#include "../regularization/reg.h"
|
||||
#include "../utilities/utilities.h"
|
||||
|
||||
#include "core/object/method_bind_ext.gen.inc"
|
||||
Ref<MLPPMatrix> MLPPWGAN::get_output_set() { return _output_set; }
|
||||
void MLPPWGAN::set_output_set(const Ref<MLPPMatrix> &val) { _output_set = val; }
|
||||
|
||||
Ref<MLPPMatrix> MLPPWGAN::get_output_set() {
|
||||
return _output_set;
|
||||
}
|
||||
void MLPPWGAN::set_output_set(const Ref<MLPPMatrix> &val) {
|
||||
_output_set = val;
|
||||
}
|
||||
|
||||
int MLPPWGAN::get_k() const {
|
||||
return _k;
|
||||
}
|
||||
void MLPPWGAN::set_k(const int val) {
|
||||
_k = val;
|
||||
}
|
||||
int MLPPWGAN::get_k() const { return _k; }
|
||||
void MLPPWGAN::set_k(const int val) { _k = val; }
|
||||
|
||||
Ref<MLPPMatrix> MLPPWGAN::generate_example(int n) {
|
||||
return model_set_test_generator(MLPPMatrix::create_gaussian_noise(n, _k));
|
||||
return model_set_test_generator(MLPPMatrix::create_gaussian_noise(n, _k));
|
||||
}
|
||||
|
||||
void MLPPWGAN::gradient_descent(real_t learning_rate, int max_epoch, bool ui) {
|
||||
//MLPPCost mlpp_cost;
|
||||
real_t cost_prev = 0;
|
||||
int epoch = 1;
|
||||
int n = _output_set->size().y;
|
||||
// MLPPCost mlpp_cost;
|
||||
real_t cost_prev = 0;
|
||||
int epoch = 1;
|
||||
int n = _output_set->size().y;
|
||||
|
||||
forward_pass();
|
||||
forward_pass();
|
||||
|
||||
const int CRITIC_INTERATIONS = 5; // Wasserstein GAN specific parameter.
|
||||
const int CRITIC_INTERATIONS = 5; // Wasserstein GAN specific parameter.
|
||||
|
||||
while (true) {
|
||||
cost_prev = cost(_y_hat, MLPPVector::create_vec_one(n));
|
||||
while (true) {
|
||||
cost_prev = cost(_y_hat, MLPPVector::create_vec_one(n));
|
||||
|
||||
Ref<MLPPMatrix> generator_input_set;
|
||||
Ref<MLPPMatrix> discriminator_input_set;
|
||||
discriminator_input_set.instance();
|
||||
Ref<MLPPMatrix> generator_input_set;
|
||||
Ref<MLPPMatrix> discriminator_input_set;
|
||||
discriminator_input_set.instance();
|
||||
|
||||
Ref<MLPPVector> ly_hat;
|
||||
Ref<MLPPVector> loutput_set;
|
||||
Ref<MLPPVector> ly_hat;
|
||||
Ref<MLPPVector> loutput_set;
|
||||
|
||||
// Training of the discriminator.
|
||||
for (int i = 0; i < CRITIC_INTERATIONS; i++) {
|
||||
generator_input_set = MLPPMatrix::create_gaussian_noise(n, _k);
|
||||
discriminator_input_set->set_from_mlpp_matrix(model_set_test_generator(generator_input_set));
|
||||
discriminator_input_set->rows_add_mlpp_matrix(_output_set); // Fake + real inputs.
|
||||
// Training of the discriminator.
|
||||
for (int i = 0; i < CRITIC_INTERATIONS; i++) {
|
||||
generator_input_set = MLPPMatrix::create_gaussian_noise(n, _k);
|
||||
discriminator_input_set->set_from_mlpp_matrix(
|
||||
model_set_test_generator(generator_input_set));
|
||||
discriminator_input_set->rows_add_mlpp_matrix(
|
||||
_output_set); // Fake + real inputs.
|
||||
|
||||
ly_hat = model_set_test_discriminator(discriminator_input_set);
|
||||
loutput_set = MLPPVector::create_vec_one(n)->scalar_multiplyn(-1); // WGAN changes y_i = 1 and y_i = 0 to y_i = 1 and y_i = -1
|
||||
Ref<MLPPVector> output_set_real = MLPPVector::create_vec_one(n);
|
||||
loutput_set->append_mlpp_vector(output_set_real); // Fake + real output scores.
|
||||
ly_hat = model_set_test_discriminator(discriminator_input_set);
|
||||
loutput_set = MLPPVector::create_vec_one(n)->scalar_multiplyn(
|
||||
-1); // WGAN changes y_i = 1 and y_i = 0 to y_i = 1 and y_i = -1
|
||||
Ref<MLPPVector> output_set_real = MLPPVector::create_vec_one(n);
|
||||
loutput_set->append_mlpp_vector(
|
||||
output_set_real); // Fake + real output scores.
|
||||
|
||||
DiscriminatorGradientResult discriminator_gradient_results = compute_discriminator_gradients(ly_hat, loutput_set);
|
||||
Vector<Ref<MLPPMatrix>> cumulative_discriminator_hidden_layer_w_grad = discriminator_gradient_results.cumulative_hidden_layer_w_grad;
|
||||
Ref<MLPPVector> output_discriminator_w_grad = discriminator_gradient_results.output_w_grad;
|
||||
DiscriminatorGradientResult discriminator_gradient_results =
|
||||
compute_discriminator_gradients(ly_hat, loutput_set);
|
||||
Vector<Ref<MLPPMatrix>> cumulative_discriminator_hidden_layer_w_grad =
|
||||
discriminator_gradient_results.cumulative_hidden_layer_w_grad;
|
||||
Ref<MLPPVector> output_discriminator_w_grad =
|
||||
discriminator_gradient_results.output_w_grad;
|
||||
|
||||
real_t lrpn = learning_rate / n;
|
||||
real_t lrpn = learning_rate / n;
|
||||
|
||||
for (int j = 0; j < cumulative_discriminator_hidden_layer_w_grad.size(); ++j) {
|
||||
cumulative_discriminator_hidden_layer_w_grad.write[j]->scalar_multiply(lrpn);
|
||||
}
|
||||
for (int j = 0; j < cumulative_discriminator_hidden_layer_w_grad.size();
|
||||
++j) {
|
||||
cumulative_discriminator_hidden_layer_w_grad.write[j]->scalar_multiply(
|
||||
lrpn);
|
||||
}
|
||||
|
||||
output_discriminator_w_grad->scalar_multiply(learning_rate / n);
|
||||
update_discriminator_parameters(cumulative_discriminator_hidden_layer_w_grad, output_discriminator_w_grad, learning_rate);
|
||||
}
|
||||
output_discriminator_w_grad->scalar_multiply(learning_rate / n);
|
||||
update_discriminator_parameters(
|
||||
cumulative_discriminator_hidden_layer_w_grad,
|
||||
output_discriminator_w_grad, learning_rate);
|
||||
}
|
||||
|
||||
// Training of the generator.
|
||||
generator_input_set = MLPPMatrix::create_gaussian_noise(n, _k);
|
||||
discriminator_input_set->set_from_mlpp_matrix(model_set_test_generator(generator_input_set));
|
||||
ly_hat = model_set_test_discriminator(discriminator_input_set);
|
||||
loutput_set = MLPPVector::create_vec_one(n);
|
||||
// Training of the generator.
|
||||
generator_input_set = MLPPMatrix::create_gaussian_noise(n, _k);
|
||||
discriminator_input_set->set_from_mlpp_matrix(
|
||||
model_set_test_generator(generator_input_set));
|
||||
ly_hat = model_set_test_discriminator(discriminator_input_set);
|
||||
loutput_set = MLPPVector::create_vec_one(n);
|
||||
|
||||
Vector<Ref<MLPPMatrix>> cumulative_generator_hidden_layer_w_grad = compute_generator_gradients(_y_hat, loutput_set);
|
||||
Vector<Ref<MLPPMatrix>> cumulative_generator_hidden_layer_w_grad =
|
||||
compute_generator_gradients(_y_hat, loutput_set);
|
||||
|
||||
real_t lrpn = learning_rate / n;
|
||||
real_t lrpn = learning_rate / n;
|
||||
|
||||
for (int i = 0; i < cumulative_generator_hidden_layer_w_grad.size(); ++i) {
|
||||
cumulative_generator_hidden_layer_w_grad.write[i]->scalar_multiply(lrpn);
|
||||
}
|
||||
for (int i = 0; i < cumulative_generator_hidden_layer_w_grad.size(); ++i) {
|
||||
cumulative_generator_hidden_layer_w_grad.write[i]->scalar_multiply(lrpn);
|
||||
}
|
||||
|
||||
update_generator_parameters(cumulative_generator_hidden_layer_w_grad, learning_rate);
|
||||
update_generator_parameters(cumulative_generator_hidden_layer_w_grad,
|
||||
learning_rate);
|
||||
|
||||
forward_pass();
|
||||
forward_pass();
|
||||
|
||||
if (ui) {
|
||||
handle_ui(epoch, cost_prev, _y_hat, MLPPVector::create_vec_one(n));
|
||||
}
|
||||
if (ui) {
|
||||
handle_ui(epoch, cost_prev, _y_hat, MLPPVector::create_vec_one(n));
|
||||
}
|
||||
|
||||
epoch++;
|
||||
if (epoch > max_epoch) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
epoch++;
|
||||
if (epoch > max_epoch) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
real_t MLPPWGAN::score() {
|
||||
MLPPUtilities util;
|
||||
forward_pass();
|
||||
int n = _output_set->size().y;
|
||||
MLPPUtilities util;
|
||||
forward_pass();
|
||||
int n = _output_set->size().y;
|
||||
|
||||
return util.performance_vec(_y_hat, MLPPVector::create_vec_one(n));
|
||||
return util.performance_vec(_y_hat, MLPPVector::create_vec_one(n));
|
||||
}
|
||||
|
||||
void MLPPWGAN::save(const String &file_name) {
|
||||
MLPPUtilities util;
|
||||
MLPPUtilities util;
|
||||
|
||||
/*
|
||||
if (!network.empty()) {
|
||||
util.saveParameters(file_name, network[0].weights, network[0].bias, 0, 1);
|
||||
for (uint32_t i = 1; i < network.size(); i++) {
|
||||
util.saveParameters(fileName, network[i].weights, network[i].bias, 1, i + 1);
|
||||
}
|
||||
util.saveParameters(file_name, outputLayer->weights, outputLayer->bias, 1, network.size() + 1);
|
||||
} else {
|
||||
util.saveParameters(file_name, outputLayer->weights, outputLayer->bias, 0, network.size() + 1);
|
||||
}
|
||||
*/
|
||||
/*
|
||||
if (!network.empty()) {
|
||||
util.saveParameters(file_name, network[0].weights, network[0].bias, 0,
|
||||
1); for (uint32_t i = 1; i < network.size(); i++) {
|
||||
util.saveParameters(fileName, network[i].weights,
|
||||
network[i].bias, 1, i + 1);
|
||||
}
|
||||
util.saveParameters(file_name, outputLayer->weights,
|
||||
outputLayer->bias, 1, network.size() + 1); } else {
|
||||
util.saveParameters(file_name, outputLayer->weights,
|
||||
outputLayer->bias, 0, network.size() + 1);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
void MLPPWGAN::create_layer(int n_hidden, MLPPActivation::ActivationFunction activation, MLPPUtilities::WeightDistributionType weight_init, MLPPReg::RegularizationType reg, real_t lambda, real_t alpha) {
|
||||
Ref<MLPPHiddenLayer> layer;
|
||||
layer.instance();
|
||||
void MLPPWGAN::create_layer(int n_hidden,
|
||||
MLPPActivation::ActivationFunction activation,
|
||||
MLPPUtilities::WeightDistributionType weight_init,
|
||||
MLPPReg::RegularizationType reg, real_t lambda,
|
||||
real_t alpha) {
|
||||
Ref<MLPPHiddenLayer> layer;
|
||||
layer.instance();
|
||||
|
||||
layer->set_n_hidden(n_hidden);
|
||||
layer->set_activation(activation);
|
||||
layer->set_weight_init(weight_init);
|
||||
layer->set_reg(reg);
|
||||
layer->set_lambda(lambda);
|
||||
layer->set_alpha(alpha);
|
||||
layer->set_n_hidden(n_hidden);
|
||||
layer->set_activation(activation);
|
||||
layer->set_weight_init(weight_init);
|
||||
layer->set_reg(reg);
|
||||
layer->set_lambda(lambda);
|
||||
layer->set_alpha(alpha);
|
||||
|
||||
int n = _output_set->size().y;
|
||||
int n = _output_set->size().y;
|
||||
|
||||
if (_network.empty()) {
|
||||
layer->set_input(MLPPMatrix::create_gaussian_noise(n, _k));
|
||||
} else {
|
||||
layer->set_input(_network.write[_network.size() - 1]->get_a());
|
||||
}
|
||||
if (_network.empty()) {
|
||||
layer->set_input(MLPPMatrix::create_gaussian_noise(n, _k));
|
||||
} else {
|
||||
layer->set_input(_network.write[_network.size() - 1]->get_a());
|
||||
}
|
||||
|
||||
_network.push_back(layer);
|
||||
layer->forward_pass();
|
||||
_network.push_back(layer);
|
||||
layer->forward_pass();
|
||||
}
|
||||
void MLPPWGAN::add_layer(Ref<MLPPHiddenLayer> layer) {
|
||||
if (!layer.is_valid()) {
|
||||
return;
|
||||
}
|
||||
if (!layer.is_valid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (_network.empty()) {
|
||||
int n = _output_set->size().y;
|
||||
if (_network.empty()) {
|
||||
int n = _output_set->size().y;
|
||||
|
||||
layer->set_input(MLPPMatrix::create_gaussian_noise(n, _k));
|
||||
} else {
|
||||
layer->set_input(_network.write[_network.size() - 1]->get_a());
|
||||
}
|
||||
layer->set_input(MLPPMatrix::create_gaussian_noise(n, _k));
|
||||
} else {
|
||||
layer->set_input(_network.write[_network.size() - 1]->get_a());
|
||||
}
|
||||
|
||||
_network.push_back(layer);
|
||||
layer->forward_pass();
|
||||
_network.push_back(layer);
|
||||
layer->forward_pass();
|
||||
}
|
||||
Ref<MLPPHiddenLayer> MLPPWGAN::get_layer(const int index) {
|
||||
ERR_FAIL_INDEX_V(index, _network.size(), Ref<MLPPHiddenLayer>());
|
||||
ERR_FAIL_INDEX_V(index, _network.size(), Ref<MLPPHiddenLayer>());
|
||||
|
||||
return _network[index];
|
||||
return _network[index];
|
||||
}
|
||||
void MLPPWGAN::remove_layer(const int index) {
|
||||
ERR_FAIL_INDEX(index, _network.size());
|
||||
ERR_FAIL_INDEX(index, _network.size());
|
||||
|
||||
_network.remove(index);
|
||||
}
|
||||
int MLPPWGAN::get_layer_count() const {
|
||||
return _network.size();
|
||||
_network.remove(index);
|
||||
}
|
||||
int MLPPWGAN::get_layer_count() const { return _network.size(); }
|
||||
|
||||
void MLPPWGAN::add_output_layer(MLPPUtilities::WeightDistributionType weight_init, MLPPReg::RegularizationType reg, real_t lambda, real_t alpha) {
|
||||
ERR_FAIL_COND(_network.empty());
|
||||
void MLPPWGAN::add_output_layer(
|
||||
MLPPUtilities::WeightDistributionType weight_init,
|
||||
MLPPReg::RegularizationType reg, real_t lambda, real_t alpha) {
|
||||
ERR_FAIL_COND(_network.empty());
|
||||
|
||||
if (!_output_layer.is_valid()) {
|
||||
_output_layer.instance();
|
||||
}
|
||||
if (!_output_layer.is_valid()) {
|
||||
_output_layer.instance();
|
||||
}
|
||||
|
||||
_output_layer->set_n_hidden(_network[_network.size() - 1]->get_n_hidden());
|
||||
_output_layer->set_activation(MLPPActivation::ACTIVATION_FUNCTION_LINEAR);
|
||||
_output_layer->set_cost(MLPPCost::COST_TYPE_WASSERSTEIN_LOSS);
|
||||
_output_layer->set_input(_network.write[_network.size() - 1]->get_a());
|
||||
_output_layer->set_weight_init(weight_init);
|
||||
_output_layer->set_lambda(lambda);
|
||||
_output_layer->set_alpha(alpha);
|
||||
_output_layer->set_n_hidden(_network[_network.size() - 1]->get_n_hidden());
|
||||
_output_layer->set_activation(MLPPActivation::ACTIVATION_FUNCTION_LINEAR);
|
||||
_output_layer->set_cost(MLPPCost::COST_TYPE_WASSERSTEIN_LOSS);
|
||||
_output_layer->set_input(_network.write[_network.size() - 1]->get_a());
|
||||
_output_layer->set_weight_init(weight_init);
|
||||
_output_layer->set_lambda(lambda);
|
||||
_output_layer->set_alpha(alpha);
|
||||
}
|
||||
|
||||
MLPPWGAN::MLPPWGAN(int p_k, const Ref<MLPPMatrix> &p_output_set) {
|
||||
_output_set = p_output_set;
|
||||
_k = p_k;
|
||||
_output_set = p_output_set;
|
||||
_k = p_k;
|
||||
|
||||
_y_hat.instance();
|
||||
_y_hat.instance();
|
||||
}
|
||||
|
||||
MLPPWGAN::MLPPWGAN() {
|
||||
_k = 0;
|
||||
_k = 0;
|
||||
|
||||
_y_hat.instance();
|
||||
_y_hat.instance();
|
||||
}
|
||||
|
||||
MLPPWGAN::~MLPPWGAN() {
|
||||
}
|
||||
MLPPWGAN::~MLPPWGAN() {}
|
||||
|
||||
Ref<MLPPMatrix> MLPPWGAN::model_set_test_generator(const Ref<MLPPMatrix> &X) {
|
||||
if (!_network.empty()) {
|
||||
_network.write[0]->set_input(X);
|
||||
_network.write[0]->forward_pass();
|
||||
if (!_network.empty()) {
|
||||
_network.write[0]->set_input(X);
|
||||
_network.write[0]->forward_pass();
|
||||
|
||||
for (int i = 1; i <= _network.size() / 2; ++i) {
|
||||
_network.write[i]->set_input(_network.write[i - 1]->get_a());
|
||||
_network.write[i]->forward_pass();
|
||||
}
|
||||
}
|
||||
for (int i = 1; i <= _network.size() / 2; ++i) {
|
||||
_network.write[i]->set_input(_network.write[i - 1]->get_a());
|
||||
_network.write[i]->forward_pass();
|
||||
}
|
||||
}
|
||||
|
||||
return _network.write[_network.size() / 2]->get_a();
|
||||
return _network.write[_network.size() / 2]->get_a();
|
||||
}
|
||||
|
||||
Ref<MLPPVector> MLPPWGAN::model_set_test_discriminator(const Ref<MLPPMatrix> &X) {
|
||||
if (!_network.empty()) {
|
||||
for (int i = _network.size() / 2 + 1; i < _network.size(); i++) {
|
||||
if (i == _network.size() / 2 + 1) {
|
||||
_network.write[i]->set_input(X);
|
||||
} else {
|
||||
_network.write[i]->set_input(_network.write[i - 1]->get_a());
|
||||
}
|
||||
_network.write[i]->forward_pass();
|
||||
}
|
||||
Ref<MLPPVector>
|
||||
MLPPWGAN::model_set_test_discriminator(const Ref<MLPPMatrix> &X) {
|
||||
if (!_network.empty()) {
|
||||
for (int i = _network.size() / 2 + 1; i < _network.size(); i++) {
|
||||
if (i == _network.size() / 2 + 1) {
|
||||
_network.write[i]->set_input(X);
|
||||
} else {
|
||||
_network.write[i]->set_input(_network.write[i - 1]->get_a());
|
||||
}
|
||||
_network.write[i]->forward_pass();
|
||||
}
|
||||
|
||||
_output_layer->set_input(_network.write[_network.size() - 1]->get_a());
|
||||
}
|
||||
_output_layer->set_input(_network.write[_network.size() - 1]->get_a());
|
||||
}
|
||||
|
||||
_output_layer->forward_pass();
|
||||
_output_layer->forward_pass();
|
||||
|
||||
return _output_layer->get_a();
|
||||
return _output_layer->get_a();
|
||||
}
|
||||
|
||||
real_t MLPPWGAN::cost(const Ref<MLPPVector> &y_hat, const Ref<MLPPVector> &y) {
|
||||
MLPPReg regularization;
|
||||
MLPPCost mlpp_cost;
|
||||
MLPPReg regularization;
|
||||
MLPPCost mlpp_cost;
|
||||
|
||||
real_t total_reg_term = 0;
|
||||
real_t total_reg_term = 0;
|
||||
|
||||
for (int i = 0; i < _network.size() - 1; ++i) {
|
||||
Ref<MLPPHiddenLayer> layer = _network[i];
|
||||
for (int i = 0; i < _network.size() - 1; ++i) {
|
||||
Ref<MLPPHiddenLayer> layer = _network[i];
|
||||
|
||||
total_reg_term += regularization.reg_termm(layer->get_weights(), layer->get_lambda(), layer->get_alpha(), layer->get_reg());
|
||||
}
|
||||
total_reg_term +=
|
||||
regularization.reg_termm(layer->get_weights(), layer->get_lambda(),
|
||||
layer->get_alpha(), layer->get_reg());
|
||||
}
|
||||
|
||||
total_reg_term += regularization.reg_termv(_output_layer->get_weights(), _output_layer->get_lambda(), _output_layer->get_alpha(), _output_layer->get_reg());
|
||||
total_reg_term += regularization.reg_termv(
|
||||
_output_layer->get_weights(), _output_layer->get_lambda(),
|
||||
_output_layer->get_alpha(), _output_layer->get_reg());
|
||||
|
||||
return mlpp_cost.run_cost_norm_vector(_output_layer->get_cost(), y_hat, y) + total_reg_term;
|
||||
return mlpp_cost.run_cost_norm_vector(_output_layer->get_cost(), y_hat, y) +
|
||||
total_reg_term;
|
||||
}
|
||||
|
||||
void MLPPWGAN::forward_pass() {
|
||||
int n = _output_set->size().y;
|
||||
int n = _output_set->size().y;
|
||||
|
||||
if (!_network.empty()) {
|
||||
Ref<MLPPHiddenLayer> layer = _network[0];
|
||||
if (!_network.empty()) {
|
||||
Ref<MLPPHiddenLayer> layer = _network[0];
|
||||
|
||||
layer->set_input(MLPPMatrix::create_gaussian_noise(n, _k));
|
||||
layer->forward_pass();
|
||||
layer->set_input(MLPPMatrix::create_gaussian_noise(n, _k));
|
||||
layer->forward_pass();
|
||||
|
||||
for (int i = 1; i < _network.size(); i++) {
|
||||
layer = _network[i];
|
||||
for (int i = 1; i < _network.size(); i++) {
|
||||
layer = _network[i];
|
||||
|
||||
layer->set_input(_network.write[i - 1]->get_a());
|
||||
layer->forward_pass();
|
||||
}
|
||||
layer->set_input(_network.write[i - 1]->get_a());
|
||||
layer->forward_pass();
|
||||
}
|
||||
|
||||
_output_layer->set_input(_network.write[_network.size() - 1]->get_a());
|
||||
} else { // Should never happen, though.
|
||||
_output_layer->set_input(MLPPMatrix::create_gaussian_noise(n, _k));
|
||||
}
|
||||
_output_layer->set_input(_network.write[_network.size() - 1]->get_a());
|
||||
} else { // Should never happen, though.
|
||||
_output_layer->set_input(MLPPMatrix::create_gaussian_noise(n, _k));
|
||||
}
|
||||
|
||||
_output_layer->forward_pass();
|
||||
_output_layer->forward_pass();
|
||||
|
||||
_y_hat->set_from_mlpp_vector(_output_layer->get_a());
|
||||
_y_hat->set_from_mlpp_vector(_output_layer->get_a());
|
||||
}
|
||||
|
||||
void MLPPWGAN::update_discriminator_parameters(const Vector<Ref<MLPPMatrix>> &hidden_layer_updations, const Ref<MLPPVector> &output_layer_updation, real_t learning_rate) {
|
||||
int n = _output_set->size().y;
|
||||
void MLPPWGAN::update_discriminator_parameters(
|
||||
const Vector<Ref<MLPPMatrix>> &hidden_layer_updations,
|
||||
const Ref<MLPPVector> &output_layer_updation, real_t learning_rate) {
|
||||
int n = _output_set->size().y;
|
||||
|
||||
_output_layer->set_weights(_output_layer->get_weights()->subn(output_layer_updation));
|
||||
_output_layer->set_bias(_output_layer->get_bias() - learning_rate * _output_layer->get_delta()->sum_elements() / n);
|
||||
_output_layer->set_weights(
|
||||
_output_layer->get_weights()->subn(output_layer_updation));
|
||||
_output_layer->set_bias(_output_layer->get_bias() -
|
||||
learning_rate *
|
||||
_output_layer->get_delta()->sum_elements() / n);
|
||||
|
||||
if (!_network.empty()) {
|
||||
Ref<MLPPHiddenLayer> layer = _network[_network.size() - 1];
|
||||
if (!_network.empty()) {
|
||||
Ref<MLPPHiddenLayer> layer = _network[_network.size() - 1];
|
||||
|
||||
Ref<MLPPMatrix> slice = hidden_layer_updations[0];
|
||||
Ref<MLPPMatrix> slice = hidden_layer_updations[0];
|
||||
|
||||
layer->set_weights(layer->get_weights()->subn(slice));
|
||||
layer->set_bias(layer->get_bias()->subtract_matrix_rowsn(layer->get_delta()->scalar_multiplyn(learning_rate / n)));
|
||||
layer->set_weights(layer->get_weights()->subn(slice));
|
||||
layer->set_bias(layer->get_bias()->subtract_matrix_rowsn(
|
||||
layer->get_delta()->scalar_multiplyn(learning_rate / n)));
|
||||
|
||||
for (int i = _network.size() - 2; i > _network.size() / 2; i--) {
|
||||
layer = _network[i];
|
||||
for (int i = _network.size() - 2; i > _network.size() / 2; i--) {
|
||||
layer = _network[i];
|
||||
|
||||
slice = hidden_layer_updations[(_network.size() - 2) - i + 1];
|
||||
slice = hidden_layer_updations[(_network.size() - 2) - i + 1];
|
||||
|
||||
layer->set_weights(layer->get_weights()->subn(slice));
|
||||
layer->set_bias(layer->get_bias()->subtract_matrix_rowsn(layer->get_delta()->scalar_multiplyn(learning_rate / n)));
|
||||
}
|
||||
}
|
||||
layer->set_weights(layer->get_weights()->subn(slice));
|
||||
layer->set_bias(layer->get_bias()->subtract_matrix_rowsn(
|
||||
layer->get_delta()->scalar_multiplyn(learning_rate / n)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MLPPWGAN::update_generator_parameters(const Vector<Ref<MLPPMatrix>> &hidden_layer_updations, real_t learning_rate) {
|
||||
if (!_network.empty()) {
|
||||
int n = _output_set->size().y;
|
||||
void MLPPWGAN::update_generator_parameters(
|
||||
const Vector<Ref<MLPPMatrix>> &hidden_layer_updations,
|
||||
real_t learning_rate) {
|
||||
if (!_network.empty()) {
|
||||
int n = _output_set->size().y;
|
||||
|
||||
Ref<MLPPMatrix> slice;
|
||||
Ref<MLPPMatrix> slice;
|
||||
|
||||
for (int i = _network.size() / 2; i >= 0; i--) {
|
||||
Ref<MLPPHiddenLayer> layer = _network[i];
|
||||
for (int i = _network.size() / 2; i >= 0; i--) {
|
||||
Ref<MLPPHiddenLayer> layer = _network[i];
|
||||
|
||||
slice = hidden_layer_updations[(_network.size() - 2) - i + 1];
|
||||
slice = hidden_layer_updations[(_network.size() - 2) - i + 1];
|
||||
|
||||
//std::cout << network[i].weights.size() << "x" << network[i].weights[0].size() << std::endl;
|
||||
//std::cout << hiddenLayerUpdations[(network.size() - 2) - i + 1].size() << "x" << hiddenLayerUpdations[(network.size() - 2) - i + 1][0].size() << std::endl;
|
||||
layer->set_weights(layer->get_weights()->subn(slice));
|
||||
layer->set_bias(layer->get_bias()->subtract_matrix_rowsn(layer->get_delta()->scalar_multiplyn(learning_rate / n)));
|
||||
}
|
||||
}
|
||||
// std::cout << network[i].weights.size() << "x" <<
|
||||
// network[i].weights[0].size() << std::endl; std::cout <<
|
||||
// hiddenLayerUpdations[(network.size() - 2) - i + 1].size() << "x" <<
|
||||
// hiddenLayerUpdations[(network.size() - 2) - i + 1][0].size() <<
|
||||
// std::endl;
|
||||
layer->set_weights(layer->get_weights()->subn(slice));
|
||||
layer->set_bias(layer->get_bias()->subtract_matrix_rowsn(
|
||||
layer->get_delta()->scalar_multiplyn(learning_rate / n)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MLPPWGAN::DiscriminatorGradientResult MLPPWGAN::compute_discriminator_gradients(const Ref<MLPPVector> &y_hat, const Ref<MLPPVector> &output_set) {
|
||||
MLPPCost mlpp_cost;
|
||||
MLPPActivation avn;
|
||||
MLPPReg regularization;
|
||||
MLPPWGAN::DiscriminatorGradientResult
|
||||
MLPPWGAN::compute_discriminator_gradients(const Ref<MLPPVector> &y_hat,
|
||||
const Ref<MLPPVector> &output_set) {
|
||||
MLPPCost mlpp_cost;
|
||||
MLPPActivation avn;
|
||||
MLPPReg regularization;
|
||||
|
||||
DiscriminatorGradientResult data;
|
||||
DiscriminatorGradientResult data;
|
||||
|
||||
_output_layer->set_delta(mlpp_cost.run_cost_deriv_vector(_output_layer->get_cost(), y_hat, output_set)->hadamard_productn(avn.run_activation_deriv_vector(_output_layer->get_activation(), _output_layer->get_z())));
|
||||
_output_layer->set_delta(
|
||||
mlpp_cost
|
||||
.run_cost_deriv_vector(_output_layer->get_cost(), y_hat, output_set)
|
||||
->hadamard_productn(avn.run_activation_deriv_vector(
|
||||
_output_layer->get_activation(), _output_layer->get_z())));
|
||||
|
||||
data.output_w_grad = _output_layer->get_input()->transposen()->mult_vec(_output_layer->get_delta());
|
||||
data.output_w_grad->add(regularization.reg_deriv_termv(_output_layer->get_weights(), _output_layer->get_lambda(), _output_layer->get_alpha(), _output_layer->get_reg()));
|
||||
data.output_w_grad = _output_layer->get_input()->transposen()->mult_vec(
|
||||
_output_layer->get_delta());
|
||||
data.output_w_grad->add(regularization.reg_deriv_termv(
|
||||
_output_layer->get_weights(), _output_layer->get_lambda(),
|
||||
_output_layer->get_alpha(), _output_layer->get_reg()));
|
||||
|
||||
if (!_network.empty()) {
|
||||
Ref<MLPPHiddenLayer> layer = _network[_network.size() - 1];
|
||||
if (!_network.empty()) {
|
||||
Ref<MLPPHiddenLayer> layer = _network[_network.size() - 1];
|
||||
|
||||
layer->set_delta(_output_layer->get_delta()->outer_product(_output_layer->get_weights())->hadamard_productn(avn.run_activation_deriv_matrix(layer->get_activation(), layer->get_z())));
|
||||
layer->set_delta(_output_layer->get_delta()
|
||||
->outer_product(_output_layer->get_weights())
|
||||
->hadamard_productn(avn.run_activation_deriv_matrix(
|
||||
layer->get_activation(), layer->get_z())));
|
||||
|
||||
Ref<MLPPMatrix> hidden_layer_w_grad = layer->get_input()->transposen()->multn(layer->get_delta());
|
||||
Ref<MLPPMatrix> hidden_layer_w_grad =
|
||||
layer->get_input()->transposen()->multn(layer->get_delta());
|
||||
|
||||
data.cumulative_hidden_layer_w_grad.push_back(hidden_layer_w_grad->addn(regularization.reg_deriv_termm(layer->get_weights(), layer->get_lambda(), layer->get_alpha(), layer->get_reg()))); // Adding to our cumulative hidden layer grads. Maintain reg terms as well.
|
||||
data.cumulative_hidden_layer_w_grad.push_back(
|
||||
hidden_layer_w_grad->addn(regularization.reg_deriv_termm(
|
||||
layer->get_weights(), layer->get_lambda(), layer->get_alpha(),
|
||||
layer->get_reg()))); // Adding to our cumulative hidden layer grads.
|
||||
// Maintain reg terms as well.
|
||||
|
||||
//std::cout << "HIDDENLAYER FIRST:" << hiddenLayerWGrad.size() << "x" << hiddenLayerWGrad[0].size() << std::endl;
|
||||
//std::cout << "WEIGHTS SECOND:" << layer.weights.size() << "x" << layer.weights[0].size() << std::endl;
|
||||
// std::cout << "HIDDENLAYER FIRST:" << hiddenLayerWGrad.size() << "x" <<
|
||||
// hiddenLayerWGrad[0].size() << std::endl; std::cout << "WEIGHTS SECOND:"
|
||||
// << layer.weights.size() << "x" << layer.weights[0].size() << std::endl;
|
||||
|
||||
for (int i = _network.size() - 2; i > _network.size() / 2; i--) {
|
||||
layer = _network[i];
|
||||
Ref<MLPPHiddenLayer> next_layer = _network[i + 1];
|
||||
for (int i = _network.size() - 2; i > _network.size() / 2; i--) {
|
||||
layer = _network[i];
|
||||
Ref<MLPPHiddenLayer> next_layer = _network[i + 1];
|
||||
|
||||
layer->set_delta(next_layer->get_delta()->multn(next_layer->get_weights()->transposen())->hadamard_productn(avn.run_activation_deriv_matrix(layer->get_activation(), layer->get_z())));
|
||||
layer->set_delta(next_layer->get_delta()
|
||||
->multn(next_layer->get_weights()->transposen())
|
||||
->hadamard_productn(avn.run_activation_deriv_matrix(
|
||||
layer->get_activation(), layer->get_z())));
|
||||
|
||||
hidden_layer_w_grad = layer->get_input()->transposen()->multn(layer->get_delta());
|
||||
data.cumulative_hidden_layer_w_grad.push_back(hidden_layer_w_grad->addn(regularization.reg_deriv_termm(layer->get_weights(), layer->get_lambda(), layer->get_alpha(), layer->get_reg()))); // Adding to our cumulative hidden layer grads. Maintain reg terms as well.
|
||||
}
|
||||
}
|
||||
hidden_layer_w_grad =
|
||||
layer->get_input()->transposen()->multn(layer->get_delta());
|
||||
data.cumulative_hidden_layer_w_grad.push_back(
|
||||
hidden_layer_w_grad->addn(regularization.reg_deriv_termm(
|
||||
layer->get_weights(), layer->get_lambda(), layer->get_alpha(),
|
||||
layer->get_reg()))); // Adding to our cumulative hidden layer
|
||||
// grads. Maintain reg terms as well.
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
return data;
|
||||
}
|
||||
|
||||
Vector<Ref<MLPPMatrix>> MLPPWGAN::compute_generator_gradients(const Ref<MLPPVector> &y_hat, const Ref<MLPPVector> &output_set) {
|
||||
class MLPPCost cost;
|
||||
MLPPActivation avn;
|
||||
MLPPReg regularization;
|
||||
Vector<Ref<MLPPMatrix>>
|
||||
MLPPWGAN::compute_generator_gradients(const Ref<MLPPVector> &y_hat,
|
||||
const Ref<MLPPVector> &output_set) {
|
||||
class MLPPCost cost;
|
||||
MLPPActivation avn;
|
||||
MLPPReg regularization;
|
||||
|
||||
Vector<Ref<MLPPMatrix>> cumulative_hidden_layer_w_grad; // Tensor containing ALL hidden grads.
|
||||
Vector<Ref<MLPPMatrix>>
|
||||
cumulative_hidden_layer_w_grad; // Tensor containing ALL hidden grads.
|
||||
|
||||
Ref<MLPPVector> cost_deriv_vector = cost.run_cost_deriv_vector(_output_layer->get_cost(), y_hat, output_set);
|
||||
Ref<MLPPVector> activation_deriv_vector = avn.run_activation_deriv_vector(_output_layer->get_activation(), _output_layer->get_z());
|
||||
Ref<MLPPVector> cost_deriv_vector =
|
||||
cost.run_cost_deriv_vector(_output_layer->get_cost(), y_hat, output_set);
|
||||
Ref<MLPPVector> activation_deriv_vector = avn.run_activation_deriv_vector(
|
||||
_output_layer->get_activation(), _output_layer->get_z());
|
||||
|
||||
_output_layer->set_delta(cost_deriv_vector->hadamard_productn(activation_deriv_vector));
|
||||
_output_layer->set_delta(
|
||||
cost_deriv_vector->hadamard_productn(activation_deriv_vector));
|
||||
|
||||
Ref<MLPPVector> output_w_grad = _output_layer->get_input()->transposen()->mult_vec(_output_layer->get_delta());
|
||||
output_w_grad->add(regularization.reg_deriv_termv(_output_layer->get_weights(), _output_layer->get_lambda(), _output_layer->get_alpha(), _output_layer->get_reg()));
|
||||
Ref<MLPPVector> output_w_grad =
|
||||
_output_layer->get_input()->transposen()->mult_vec(
|
||||
_output_layer->get_delta());
|
||||
output_w_grad->add(regularization.reg_deriv_termv(
|
||||
_output_layer->get_weights(), _output_layer->get_lambda(),
|
||||
_output_layer->get_alpha(), _output_layer->get_reg()));
|
||||
|
||||
if (!_network.empty()) {
|
||||
Ref<MLPPHiddenLayer> layer = _network[_network.size() - 1];
|
||||
if (!_network.empty()) {
|
||||
Ref<MLPPHiddenLayer> layer = _network[_network.size() - 1];
|
||||
|
||||
Ref<MLPPMatrix> activation_deriv_matrix = avn.run_activation_deriv_matrix(layer->get_activation(), layer->get_z());
|
||||
layer->set_delta(_output_layer->get_delta()->outer_product(_output_layer->get_weights())->hadamard_productn(activation_deriv_matrix));
|
||||
Ref<MLPPMatrix> activation_deriv_matrix = avn.run_activation_deriv_matrix(
|
||||
layer->get_activation(), layer->get_z());
|
||||
layer->set_delta(_output_layer->get_delta()
|
||||
->outer_product(_output_layer->get_weights())
|
||||
->hadamard_productn(activation_deriv_matrix));
|
||||
|
||||
Ref<MLPPMatrix> hidden_layer_w_grad = layer->get_input()->transposen()->multn(layer->get_delta());
|
||||
Ref<MLPPMatrix> hidden_layer_w_grad =
|
||||
layer->get_input()->transposen()->multn(layer->get_delta());
|
||||
|
||||
cumulative_hidden_layer_w_grad.push_back(hidden_layer_w_grad->addn(regularization.reg_deriv_termm(layer->get_weights(), layer->get_lambda(), layer->get_alpha(), layer->get_reg()))); // Adding to our cumulative hidden layer grads. Maintain reg terms as well.
|
||||
cumulative_hidden_layer_w_grad.push_back(
|
||||
hidden_layer_w_grad->addn(regularization.reg_deriv_termm(
|
||||
layer->get_weights(), layer->get_lambda(), layer->get_alpha(),
|
||||
layer->get_reg()))); // Adding to our cumulative hidden layer grads.
|
||||
// Maintain reg terms as well.
|
||||
|
||||
for (int i = _network.size() - 2; i >= 0; i--) {
|
||||
layer = _network[i];
|
||||
Ref<MLPPHiddenLayer> next_layer = _network[i + 1];
|
||||
for (int i = _network.size() - 2; i >= 0; i--) {
|
||||
layer = _network[i];
|
||||
Ref<MLPPHiddenLayer> next_layer = _network[i + 1];
|
||||
|
||||
activation_deriv_matrix = avn.run_activation_deriv_matrix(layer->get_activation(), layer->get_z());
|
||||
activation_deriv_matrix = avn.run_activation_deriv_matrix(
|
||||
layer->get_activation(), layer->get_z());
|
||||
|
||||
layer->set_delta(next_layer->get_delta()->multn(next_layer->get_weights()->transposen())->hadamard_productn(activation_deriv_matrix));
|
||||
hidden_layer_w_grad = layer->get_input()->transposen()->multn(layer->get_delta());
|
||||
layer->set_delta(next_layer->get_delta()
|
||||
->multn(next_layer->get_weights()->transposen())
|
||||
->hadamard_productn(activation_deriv_matrix));
|
||||
hidden_layer_w_grad =
|
||||
layer->get_input()->transposen()->multn(layer->get_delta());
|
||||
|
||||
cumulative_hidden_layer_w_grad.push_back(hidden_layer_w_grad->addn(regularization.reg_deriv_termm(layer->get_weights(), layer->get_lambda(), layer->get_alpha(), layer->get_reg()))); // Adding to our cumulative hidden layer grads. Maintain reg terms as well.
|
||||
}
|
||||
}
|
||||
cumulative_hidden_layer_w_grad.push_back(
|
||||
hidden_layer_w_grad->addn(regularization.reg_deriv_termm(
|
||||
layer->get_weights(), layer->get_lambda(), layer->get_alpha(),
|
||||
layer->get_reg()))); // Adding to our cumulative hidden layer
|
||||
// grads. Maintain reg terms as well.
|
||||
}
|
||||
}
|
||||
|
||||
return cumulative_hidden_layer_w_grad;
|
||||
return cumulative_hidden_layer_w_grad;
|
||||
}
|
||||
|
||||
void MLPPWGAN::handle_ui(int epoch, real_t cost_prev, const Ref<MLPPVector> &y_hat, const Ref<MLPPVector> &output_set) {
|
||||
MLPPUtilities::cost_info(epoch, cost_prev, cost(y_hat, output_set));
|
||||
void MLPPWGAN::handle_ui(int epoch, real_t cost_prev,
|
||||
const Ref<MLPPVector> &y_hat,
|
||||
const Ref<MLPPVector> &output_set) {
|
||||
MLPPUtilities::cost_info(epoch, cost_prev, cost(y_hat, output_set));
|
||||
|
||||
PLOG_MSG("Layer " + itos(_network.size() + 1) + ":");
|
||||
PLOG_MSG("Layer " + itos(_network.size() + 1) + ":");
|
||||
|
||||
MLPPUtilities::print_ui_vb(_output_layer->get_weights(), _output_layer->get_bias());
|
||||
MLPPUtilities::print_ui_vb(_output_layer->get_weights(),
|
||||
_output_layer->get_bias());
|
||||
|
||||
if (!_network.empty()) {
|
||||
for (int i = _network.size() - 1; i >= 0; i--) {
|
||||
Ref<MLPPHiddenLayer> layer = _network[i];
|
||||
if (!_network.empty()) {
|
||||
for (int i = _network.size() - 1; i >= 0; i--) {
|
||||
Ref<MLPPHiddenLayer> layer = _network[i];
|
||||
|
||||
PLOG_MSG("Layer " + itos(i + 1) + ":");
|
||||
PLOG_MSG("Layer " + itos(i + 1) + ":");
|
||||
|
||||
MLPPUtilities::print_ui_mb(layer->get_weights(), layer->get_bias());
|
||||
}
|
||||
}
|
||||
MLPPUtilities::print_ui_mb(layer->get_weights(), layer->get_bias());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MLPPWGAN::_bind_methods() {
|
||||
ClassDB::bind_method(D_METHOD("get_output_set"), &MLPPWGAN::get_output_set);
|
||||
ClassDB::bind_method(D_METHOD("set_output_set", "val"), &MLPPWGAN::set_output_set);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output_set", PROPERTY_HINT_RESOURCE_TYPE, "MLPPMatrix"), "set_output_set", "get_output_set");
|
||||
ClassDB::bind_method(D_METHOD("get_output_set"), &MLPPWGAN::get_output_set);
|
||||
ClassDB::bind_method(D_METHOD("set_output_set", "val"),
|
||||
&MLPPWGAN::set_output_set);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "output_set",
|
||||
PROPERTY_HINT_RESOURCE_TYPE, "MLPPMatrix"),
|
||||
"set_output_set", "get_output_set");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("get_k"), &MLPPWGAN::get_k);
|
||||
ClassDB::bind_method(D_METHOD("set_k", "val"), &MLPPWGAN::set_k);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "k"), "set_k", "get_k");
|
||||
ClassDB::bind_method(D_METHOD("get_k"), &MLPPWGAN::get_k);
|
||||
ClassDB::bind_method(D_METHOD("set_k", "val"), &MLPPWGAN::set_k);
|
||||
ADD_PROPERTY(PropertyInfo(Variant::INT, "k"), "set_k", "get_k");
|
||||
|
||||
ClassDB::bind_method(D_METHOD("generate_example", "n"), &MLPPWGAN::generate_example);
|
||||
ClassDB::bind_method(D_METHOD("gradient_descent", "learning_rate", "max_epoch", "ui"), &MLPPWGAN::gradient_descent, false);
|
||||
ClassDB::bind_method(D_METHOD("score"), &MLPPWGAN::score);
|
||||
ClassDB::bind_method(D_METHOD("save", "file_name"), &MLPPWGAN::save);
|
||||
ClassDB::bind_method(D_METHOD("generate_example", "n"),
|
||||
&MLPPWGAN::generate_example);
|
||||
ClassDB::bind_method(
|
||||
D_METHOD("gradient_descent", "learning_rate", "max_epoch", "ui"),
|
||||
&MLPPWGAN::gradient_descent, false);
|
||||
ClassDB::bind_method(D_METHOD("score"), &MLPPWGAN::score);
|
||||
ClassDB::bind_method(D_METHOD("save", "file_name"), &MLPPWGAN::save);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("create_layer", "activation", "weight_init", "reg", "lambda", "alpha"), &MLPPWGAN::create_layer, MLPPUtilities::WEIGHT_DISTRIBUTION_TYPE_DEFAULT, MLPPReg::REGULARIZATION_TYPE_NONE, 0.5, 0.5);
|
||||
ClassDB::bind_method(D_METHOD("add_layer", "layer"), &MLPPWGAN::add_layer);
|
||||
ClassDB::bind_method(D_METHOD("get_layer", "index"), &MLPPWGAN::get_layer);
|
||||
ClassDB::bind_method(D_METHOD("remove_layer", "index"), &MLPPWGAN::remove_layer);
|
||||
ClassDB::bind_method(D_METHOD("get_layer_count"), &MLPPWGAN::score);
|
||||
ClassDB::bind_method(D_METHOD("create_layer", "activation", "weight_init",
|
||||
"reg", "lambda", "alpha"),
|
||||
&MLPPWGAN::create_layer,
|
||||
MLPPUtilities::WEIGHT_DISTRIBUTION_TYPE_DEFAULT,
|
||||
MLPPReg::REGULARIZATION_TYPE_NONE, 0.5, 0.5);
|
||||
ClassDB::bind_method(D_METHOD("add_layer", "layer"), &MLPPWGAN::add_layer);
|
||||
ClassDB::bind_method(D_METHOD("get_layer", "index"), &MLPPWGAN::get_layer);
|
||||
ClassDB::bind_method(D_METHOD("remove_layer", "index"),
|
||||
&MLPPWGAN::remove_layer);
|
||||
ClassDB::bind_method(D_METHOD("get_layer_count"), &MLPPWGAN::score);
|
||||
|
||||
ClassDB::bind_method(D_METHOD("add_output_layer", "weight_init", "reg", "lambda", "alpha"), &MLPPWGAN::add_output_layer, MLPPUtilities::WEIGHT_DISTRIBUTION_TYPE_DEFAULT, MLPPReg::REGULARIZATION_TYPE_NONE, 0.5, 0.5);
|
||||
ClassDB::bind_method(
|
||||
D_METHOD("add_output_layer", "weight_init", "reg", "lambda", "alpha"),
|
||||
&MLPPWGAN::add_output_layer,
|
||||
MLPPUtilities::WEIGHT_DISTRIBUTION_TYPE_DEFAULT,
|
||||
MLPPReg::REGULARIZATION_TYPE_NONE, 0.5, 0.5);
|
||||
}
|
||||
|
@ -31,11 +31,15 @@
|
||||
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
||||
/*************************************************************************/
|
||||
|
||||
#ifdef USING_SFW
|
||||
#include "sfw.h"
|
||||
#else
|
||||
#include "core/containers/vector.h"
|
||||
#include "core/math/math_defs.h"
|
||||
#include "core/string/ustring.h"
|
||||
|
||||
#include "core/object/reference.h"
|
||||
#endif
|
||||
|
||||
#include "../lin_alg/mlpp_matrix.h"
|
||||
#include "../lin_alg/mlpp_tensor3.h"
|
||||
|
Loading…
Reference in New Issue
Block a user