axis=1) # NaN を含む変数を削除 # 標準偏差が 0 の説明変数を削除 std_0_variable_flags = original_x.std() == 0 x = original_x.drop(original_x.columns[std_0_variable_flags], axis=1) variables = pd.concat([y, x], axis=1) numbers_of_x = np.arange(numbers_of_y[-1] + 1, variables.shape[1]) # standardize x and y autoscaled_variables = (variables - variables.mean(axis=0)) / variables.std( axis=0, ddof=1) autoscaled_target_y_value = (target_y_value - variables.mean( axis=0)[numbers_of_y]) / variables.std(axis=0, ddof=1)[numbers_of_y] # construct GTMR model model = GTM(shape_of_map, shape_of_rbf_centers, variance_of_rbfs, lambda_in_em_algorithm, number_of_iterations, display_flag) model.fit(autoscaled_variables) if model.success_flag: # calculate of responsibilities responsibilities = model.responsibility(autoscaled_variables) means = responsibilities.dot(model.map_grids) modes = model.map_grids[responsibilities.argmax(axis=1), :] mean_of_estimated_mean_of_y, mode_of_estimated_mean_of_y, responsibilities_y, py = \ model.gtmr_predict(autoscaled_variables.iloc[:, numbers_of_x], numbers_of_x, numbers_of_y) plt.rcParams['font.size'] = 18 for index, y_number in enumerate(numbers_of_y): predicted_y_test = mode_of_estimated_mean_of_y[:, index] * variables.iloc[:, y_number].std( ) + variables.iloc[:, y_number].mean()
plt.xlabel('y1') plt.ylabel('y2') plt.show() variables = np.c_[x, y1, y2] variables_train, variables_test = train_test_split( variables, test_size=number_of_test_samples, random_state=100) # standardize x and y autoscaled_variables_train = (variables_train - variables_train.mean(axis=0) ) / variables_train.std(axis=0, ddof=1) autoscaled_variables_test = (variables_test - variables_train.mean(axis=0) ) / variables_train.std(axis=0, ddof=1) # optimize hyperparameter in GTMR with CV model = GTM() model.gtmr_cv_opt(autoscaled_variables_train, numbers_of_y, candidates_of_shape_of_map, candidates_of_shape_of_rbf_centers, candidates_of_variance_of_rbfs, candidates_of_lambda_in_em_algorithm, fold_number, number_of_iterations) model.display_flag = display_flag print('optimized shape of map :', model.shape_of_map) print('optimized shape of RBF centers :', model.shape_of_rbf_centers) print('optimized variance of RBFs :', model.variance_of_rbfs) print('optimized lambda in EM algorithm :', model.lambda_in_em_algorithm) # construct GTMR model model.fit(autoscaled_variables_train) if model.success_flag:
# you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0.txt # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #=========================================================================*/ # load gtm module from gtm import GTM # # Test the Lock method # db = GTM() globalName = '^Capital("US")' setValue = 'Washington' db.lock(globalName) db.set(globalName, setValue) db.kill(globalName)
# load an iris dataset iris = load_iris() # input_dataset = pd.DataFrame(iris.data, columns=iris.feature_names) input_dataset = iris.data color = iris.target # autoscaling input_dataset = (input_dataset - input_dataset.mean(axis=0)) / input_dataset.std(axis=0, ddof=1) # construct SGTM model model = GTM(shape_of_map, shape_of_rbf_centers, variance_of_rbfs, lambda_in_em_algorithm, number_of_iterations, display_flag, sparse_flag=True) model.fit(input_dataset) if model.success_flag: # calculate of responsibilities responsibilities = model.responsibility(input_dataset) # plot the mean of responsibilities means = responsibilities.dot(model.map_grids) plt.figure(figsize=figure.figaspect(1)) plt.scatter(means[:, 0], means[:, 1], c=color) plt.ylim(-1.1, 1.1) plt.xlim(-1.1, 1.1)
# # http://www.apache.org/licenses/LICENSE-2.0.txt # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #=========================================================================*/ # load gtm module from gtm import GTM # # Test the Set, Get and Kill methods # db = GTM() globalName = "^Capital" setValue = "London" db.set(globalName, setValue) getValue = db.get(globalName) print globalName, " = ", getValue db.kill(globalName)
if __name__ == "__main__": #Get the call in table file if 'gtm_access_ci' not in os.environ: print "Please set environment variable gtm_access_ci to the location of gtm_access.ci" exit(0) if not os.path.exists(os.environ['gtm_access_ci']): print "Error: {0} does not exist".format(os.environ['gtm_access_ci']) exit(0) os.environ['GTMCI'] = os.environ['gtm_access_ci'] #Change working folder to database location if 'gtm_data_dir' not in os.environ: print "Please set environment variable gtm_data_dir to the data folder" if not os.path.exists(os.environ['gtm_data_dir']): print "Error: {0} does not exist".format(os.environ['gtm_data_dir']) exit(0) os.chdir(os.environ['gtm_data_dir']) db = GTM() print "Enter email" username = raw_input() print "Enter password" password = raw_input() db.execute('d loginLowLevel^user("{0}","{1}")'.format(username, password)) print "authenticated=", db.get('%sess("authenticated")') print "uid=", db.get('%sess("uid")')
# # http://www.apache.org/licenses/LICENSE-2.0.txt # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #=========================================================================*/ # load gtm module from gtm import GTM # # Test the Set and Get methods # db = GTM() globalName = "^Capital" setValue = "London" db.set( globalName, setValue ) getValue = db.get( globalName ) print globalName, " = ", getValue
<<<<<<< HEAD # autoscaling autoscaled_X = (original_X - original_X.mean(axis=0)) / original_X.std(axis=0, ddof=1) autoscaled_y = (original_y - original_y.mean()) / original_y.std(ddof=1) autoscaled_target_y_value = (target_y_value - original_y.mean()) / original_y.std(ddof=1) ======= variables = np.c_[x, y] # standardize x and y autoscaled_variables = (variables - variables.mean(axis=0)) / variables.std(axis=0, ddof=1) autoscaled_target_y_value = (target_y_value - variables.mean(axis=0)[numbers_of_y]) / variables.std(axis=0, ddof=1)[ numbers_of_y] >>>>>>> 2.0.X # construct GTMR model model = GTM(shape_of_map, shape_of_rbf_centers, variance_of_rbfs, lambda_in_em_algorithm, number_of_iterations, display_flag) model.fit(autoscaled_variables) if model.success_flag: # calculate of responsibilities responsibilities = model.responsibility(autoscaled_variables) means = responsibilities.dot(model.map_grids) modes = model.map_grids[responsibilities.argmax(axis=1), :] <<<<<<< HEAD # inverse analysis estimated_x_mean, estimated_x_mode, responsibilities_inverse, py = model.inverse_gtmr(autoscaled_target_y_value) estimated_x_mean = estimated_x_mean * original_X.std(axis=0, ddof=1) + original_X.mean(axis=0) estimated_x_mode = estimated_x_mode * original_X.std(axis=0, ddof=1) + original_X.mean(axis=0) # print("estimated x-mean: {0}".format(estimated_x_mean)) print("estimated x-mode: {0}".format(estimated_x_mode))
raw_y = 0.3 * original_X[:, 0] - 0.1 * original_X[:, 1] + 0.2 * original_X[:, 2] original_y = raw_y + noise_ratio_of_y * raw_y.std(ddof=1) * np.random.randn(len(raw_y)) # plot plt.rcParams["font.size"] = 18 fig = plt.figure() ax = fig.add_subplot(111, projection='3d') p = ax.scatter(original_X[:, 0], original_X[:, 1], original_X[:, 2], c=original_y) fig.colorbar(p) plt.show() # autoscaling autoscaled_X = (original_X - original_X.mean(axis=0)) / original_X.std(axis=0, ddof=1) autoscaled_target_y_value = (target_y_value - original_y.mean(axis=0)) / original_y.std(axis=0, ddof=1) # construct GTM model model = GTM(shape_of_map, shape_of_rbf_centers, variance_of_rbfs, lambda_in_em_algorithm, number_of_iterations, display_flag) model.fit(autoscaled_X) if model.success_flag: # calculate of responsibilities responsibilities = model.responsibility(autoscaled_X) # plot the mean of responsibilities means = responsibilities.dot(model.map_grids) plt.figure() # plt.figure(figsize=figure.figaspect(1)) plt.scatter(means[:, 0], means[:, 1], c=original_y) plt.colorbar() plt.ylim(-1.1, 1.1) plt.xlim(-1.1, 1.1) plt.xlabel("z1 (mean)") plt.ylabel("z2 (mean)")
# Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0.txt # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #=========================================================================*/ # load gtm module from gtm import GTM # # Test the Set and Get methods # db = GTM() db.set("^Capital","London") capital = db.get("^Capital") print "Capital = ", capital
# # http://www.apache.org/licenses/LICENSE-2.0.txt # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #=========================================================================*/ # load gtm module from gtm import GTM db = GTM() print db.about() print db.version() getValue = "Initially empty" for k in xrange(1,1000): db.set("^FibonacciA", "1") db.set("^FibonacciB", "1") termnumber = 100 for i in xrange(1,termnumber):
parameters_and_k3nerror = [] all_calculation_numbers = len(candidates_of_shape_of_map) * len( candidates_of_shape_of_rbf_centers) * len( candidates_of_variance_of_rbfs) * len( candidates_of_lambda_in_em_algorithm) calculation_number = 0 for shape_of_map_grid in candidates_of_shape_of_map: for shape_of_rbf_centers_grid in candidates_of_shape_of_rbf_centers: for variance_of_rbfs_grid in candidates_of_variance_of_rbfs: for lambda_in_em_algorithm_grid in candidates_of_lambda_in_em_algorithm: calculation_number += 1 print([calculation_number, all_calculation_numbers]) # construct GTM model model = GTM( [shape_of_map_grid, shape_of_map_grid], [shape_of_rbf_centers_grid, shape_of_rbf_centers_grid], variance_of_rbfs_grid, lambda_in_em_algorithm_grid, number_of_iterations, display_flag) model.fit(input_dataset) if model.success_flag: # calculate of responsibilities responsibilities = model.responsibility(input_dataset) # calculate the mean of responsibilities means = responsibilities.dot(model.map_grids) # calculate k3n-error k3nerror_of_gtm = k3nerror(input_dataset, means, k_in_k3nerror) else: k3nerror_of_gtm = 10**100 parameters_and_k3nerror.append([ shape_of_map_grid, shape_of_rbf_centers_grid,
# distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #=========================================================================*/ # load gtm module from gtm import GTM # # Test the Lock method # db = GTM() globalName = "^ValueCounter" setValue = "0" getValue = "Initially empty" db.lock( globalName ) db.set( globalName, setValue ) for i in xrange(0,9): db.execute("set ^ValueCounter=^ValueCounter+1") getValue = db.get( globalName ) print "counter = ", getValue print "Final Counter Value = ", getValue
# Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #=========================================================================*/ # load gtm module from gtm import GTM # # Test the Lock method # db = GTM() globalName = "^ValueCounter" setValue = "0" getValue = "Initially empty" db.lock(globalName) db.set(globalName, setValue) for i in xrange(0, 9): db.execute("set ^ValueCounter=^ValueCounter+1") getValue = db.get(globalName) print "counter = ", getValue print "Final Counter Value = ", getValue
# distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #=========================================================================*/ # load gtm module from gtm import GTM # # Test the Execute method # db = GTM() # # Exercise the string API # textOfCode = 'write $ZVERSION,!' db.execute( textOfCode ) # # Exercise the same pattern with direct strings # db.execute( 'write $ZVERSION,!')
# Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #=========================================================================*/ # load gtm module from gtm import GTM # # Test the Execute method # db = GTM() # # Exercise the string API # textOfCode = 'write $ZVERSION,!' db.execute(textOfCode) # # Exercise the same pattern with direct strings # db.execute('write $ZVERSION,!')
# Copyright OSEHRA # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0.txt # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #=========================================================================*/ # load gtm module from gtm import GTM # # Test the Set and Get methods # db = GTM() db.set("^Capital", "London") capital = db.get("^Capital") print "Capital = ", capital
plt.show() # divide a dataset into training data and test data Xtrain = original_X[:500, :] ytrain = original_y[:500] Xtest = original_X[500:, :] ytest = original_y[500:] # autoscaling # autoscaled_X = (original_X - original_X.mean(axis=0)) / original_X.std(axis=0,ddof=1) autoscaled_Xtrain = (Xtrain - Xtrain.mean(axis=0)) / Xtrain.std(axis=0, ddof=1) # autoscaled_Xtest = (Xtest - X.mean(axis=0)) / X.std(axis=0,ddof=1) # autoscaled_ytrain = (ytrain - ytrain.mean()) / ytrain.std(ddof=1) # construct GTM model model = GTM(shape_of_map, shape_of_rbf_centers, variance_of_rbfs, lambda_in_em_algorithm, number_of_iterations, display_flag) model.fit(autoscaled_Xtrain) if model.success_flag: # calculate of responsibilities responsibilities = model.responsibility(autoscaled_Xtrain) # plot the mean of responsibilities means = responsibilities.dot(model.map_grids) plt.figure() # plt.figure(figsize=figure.figaspect(1)) plt.scatter(means[:, 0], means[:, 1], c=ytrain) plt.colorbar() plt.ylim(-1.1, 1.1) plt.xlim(-1.1, 1.1) plt.xlabel("z1 (mean)") plt.ylabel("z2 (mean)")
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #=========================================================================*/ import sys # load gtm module from gtm import GTM # # Test the Set, Get and Order methods # db = GTM() # # Exercise the string API # globalName = '^Capital("US")' setValue = 'Washington' db.set( globalName, setValue ) globalName = '^Capital("UK")' setValue = 'London' db.set( globalName, setValue )
# You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0.txt # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #=========================================================================*/ # load gtm module from gtm import GTM # # Simply test constructor, destructor and connection to GT.M # db = GTM() version = db.version() print "Version = ", version about = db.about() print "About = ", about
# You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0.txt # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #=========================================================================*/ # load gtm module from gtm import GTM db = GTM() print db.about() print db.version() getValue = "Initially empty" for k in xrange(1, 1000): db.set("^FibonacciA", "1") db.set("^FibonacciB", "1") termnumber = 100 for i in xrange(1, termnumber):
# # http://www.apache.org/licenses/LICENSE-2.0.txt # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # #=========================================================================*/ # load gtm module from gtm import GTM # # Test the Lock method # db = GTM() globalName = '^Capital("US")' setValue = 'Washington' db.lock( globalName ) db.set( globalName, setValue ) db.kill( globalName )