module.py
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 ini={}
00012 cm_kernel=None
00013
00014
00015 import os
00016 import csv
00017 import math
00018
00019
00020 def init(i):
00021 return {'cm_return':0}
00022
00023
00024 def analyze(i):
00025
00026 """
00027 Analyze
00028
00029 Input: {
00030 data
00031 ct_dimensions_input
00032 ct_dimensions_output
00033 desc
00034 model_name - (earth, svm)
00035 (record_data_to_file_prefix) - if !='', use this filename prefix instead of randomly generated
00036 }
00037
00038 Output: {
00039 cm_return - return code >0 if error
00040 }
00041
00042 """
00043
00044 data=i.get('data',{})
00045 desc=i.get('desc',{})
00046
00047 model_name=i.get('model_name','')
00048 if model_name=='':
00049 return {'cm_return':1, 'cm_error':'model name is not specified'}
00050
00051 dim1=i.get('ct_dimensions_input',[])
00052 dim2=i.get('ct_dimensions_output',[])
00053
00054 dim=[]
00055 for d in dim1: dim.append(d)
00056 for d in dim2: dim.append(d)
00057
00058
00059 r=cm_kernel.gen_cm_tmp_file({})
00060 fitmp=r['cm_path1']+'.csv'
00061
00062
00063 fotmp=i.get('record_data_to_file_prefix','')
00064 if fotmp=='':
00065 r=cm_kernel.gen_cm_tmp_file({})
00066 fotmp=r['cm_path1']
00067
00068 cm_kernel.print_for_con('')
00069 cm_kernel.print_for_con('Generating tmp CSV file for learning (input='+fitmp+', output='+fotmp+'.r.model.obj'+') ...')
00070
00071
00072 ii={'cm_run_module_uoa':ini['cfg']['cm_modules']['ctuning.space'],
00073 'cm_action':'convert_ct_multi_array_to_csv',
00074 'cm_multi_array_s': data,
00075 'ct_dimensions': dim,
00076 'ct_dim_desc': desc,
00077 'ct_output_file': fitmp,
00078 'csv_no_header':'yes',
00079 'csv_separator':';',
00080 'csv_decimal_mark':'.'
00081 }
00082 r=cm_kernel.access(ii)
00083 if r['cm_return']>0: return r
00084
00085
00086 model_code=os.path.join(ini['path'], ini['cfg']['stat_analysis']).replace(cm_kernel.convert_str_to_special('model_name'), model_name)
00087
00088 cmd='r --vanilla --args '+fitmp+' '+fotmp+' < '+model_code
00089 os.system(cmd)
00090
00091 return {'cm_return':0}