-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #310 from MeasureTransport/dannys4/atmBinding
Bindings for ATM
- Loading branch information
Showing
31 changed files
with
560 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
build | ||
*.egg-info* | ||
.vscode | ||
docs/_build | ||
bin | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#include "CommonJuliaUtilities.h" | ||
#include "MParT/MapOptions.h" | ||
#include "MParT/MapObjective.h" | ||
#include "MParT/TrainMap.h" | ||
#include "MParT/TrainMapAdaptive.h" | ||
|
||
#include <Kokkos_Core.hpp> | ||
|
||
using namespace mpart; | ||
|
||
namespace jlcxx { | ||
// Tell CxxWrap.jl the supertype structure for ConditionalMapBase | ||
template<> struct SuperType<mpart::ATMOptions> {typedef mpart::MapOptions type;}; | ||
} | ||
|
||
void mpart::binding::TrainMapAdaptiveWrapper(jlcxx::Module &mod) { | ||
// Can only do single inheritence, so I arbitrarily picked inheritence from MapOptions | ||
// If you need to convert to TrainOptions, I allow a conversion | ||
mod.add_type<ATMOptions>("__ATMOptions", jlcxx::julia_base_type<MapOptions>()) | ||
.method("__opt_alg!", [](ATMOptions &opts, std::string alg){opts.opt_alg = alg;}) | ||
.method("__opt_ftol_rel!", [](ATMOptions &opts, double tol){opts.opt_ftol_rel = tol;}) | ||
.method("__opt_ftol_abs!", [](ATMOptions &opts, double tol){opts.opt_ftol_abs = tol;}) | ||
.method("__opt_xtol_rel!", [](ATMOptions &opts, double tol){opts.opt_xtol_rel = tol;}) | ||
.method("__opt_xtol_abs!", [](ATMOptions &opts, double tol){opts.opt_xtol_abs = tol;}) | ||
.method("__opt_maxeval!", [](ATMOptions &opts, int eval){opts.opt_maxeval = eval;}) | ||
.method("__verbose!", [](ATMOptions &opts, int verbose){opts.verbose = verbose;}) | ||
.method("__maxPatience!", [](ATMOptions &opts, int maxPatience){opts.maxPatience = maxPatience;}) | ||
.method("__maxSize!", [](ATMOptions &opts, int maxSize){opts.maxSize = maxSize;}) | ||
.method("__maxDegrees!", [](ATMOptions &opts, MultiIndex &maxDegrees){opts.maxDegrees = maxDegrees;}) | ||
.method("TrainOptions", [](ATMOptions &opts){ return static_cast<TrainOptions>(opts);}) | ||
; | ||
|
||
|
||
mod.method("TrainMapAdaptive", [](jlcxx::ArrayRef<MultiIndexSet> arr, std::shared_ptr<MapObjective<Kokkos::HostSpace>> objective, ATMOptions options) { | ||
std::vector<MultiIndexSet> vec (arr.begin(), arr.end()); | ||
auto map = TrainMapAdaptive(vec, objective, options); | ||
for(int i = 0; i < vec.size(); i++) arr[i] = vec[i]; | ||
return map; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
classdef ATMOptions < TrainOptions & MapOptions | ||
properties (Access = public) | ||
maxPatience = 10; | ||
maxSize = 10; | ||
maxDegrees = MultiIndex(0); | ||
end | ||
methods | ||
function obj = set.maxPatience(obj,value) | ||
obj.maxPatience = value; | ||
end | ||
function obj = set.maxSize(obj,value) | ||
obj.maxSize = value; | ||
end | ||
function obj = set.maxDegrees(obj,value) | ||
obj.maxDegrees = value; | ||
end | ||
function optionsArray = getMexOptions(obj) | ||
optionsArray{1} = char(obj.basisType); | ||
optionsArray{2} = char(obj.posFuncType); | ||
optionsArray{3} = char(obj.quadType); | ||
optionsArray{4} = obj.quadAbsTol; | ||
optionsArray{5} = obj.quadRelTol; | ||
optionsArray{6} = obj.quadMaxSub; | ||
optionsArray{7} = obj.quadMinSub; | ||
optionsArray{8} = obj.quadPts; | ||
optionsArray{9} = obj.contDeriv; | ||
optionsArray{10} = obj.basisLB; | ||
optionsArray{11} = obj.basisUB; | ||
optionsArray{12} = obj.basisNorm; | ||
optionsArray{12+1} = char(obj.opt_alg); | ||
optionsArray{12+2} = obj.opt_stopval; | ||
optionsArray{12+3} = obj.opt_ftol_rel; | ||
optionsArray{12+4} = obj.opt_ftol_abs; | ||
optionsArray{12+5} = obj.opt_xtol_rel; | ||
optionsArray{12+6} = obj.opt_xtol_abs; | ||
optionsArray{12+7} = obj.opt_maxeval; | ||
optionsArray{12+8} = obj.opt_maxtime; | ||
optionsArray{12+9} = obj.verbose; | ||
optionsArray{12+9+1} = obj.maxPatience; | ||
optionsArray{12+9+2} = obj.maxSize; | ||
optionsArray{12+9+3} = obj.maxDegrees.get_id(); | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function map = TrainMapAdaptive(mset0, objective, atm_options) | ||
mexOptions = atm_options.getMexOptions; | ||
mset_ids = arrayfun(@(mset) mset.get_id(), mset0); | ||
input_str=['map_ptr = MParT_(',char(39),'ConditionalMap_TrainMapAdaptive',char(39),',mset_ids,objective.get_id()']; | ||
for o=1:length(mexOptions) | ||
input_o=[',mexOptions{',num2str(o),'}']; | ||
input_str=[input_str,input_o]; | ||
end | ||
input_str=[input_str,');']; | ||
eval(input_str); | ||
map = ConditionalMap(map_ptr,"id"); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.