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