Beispiel #1
0
class config:
    model_dir = None
    base_dataset_dir = Path(
        os.path.dirname(__file__)) / '..' / 'data_process' / 'HPA_ieee'
    dataset_dir = Path(os.path.dirname(__file__)) / 'dataset'
    ckpt_dir = Path(os.path.dirname(__file__)) / 'ckpt'
    summary_dir = Path(os.path.dirname(__file__)) / 'summary'
    n_labels = 6

    # dataset config
    stride = 16
    patch_size = 32
    img_size = 3000
    cut_img_threshold = 0.9
    padding = 750
    train_samples = [30, 230]
    eval_samples = [0, 30]
    # batch_size = 1024

    # training config
    # shuffle_size = batch_size * 3
    learning_rate = 0.1
    min_patches_per_sample = 1000
    max_patches_per_sample = 2048
    n_candidates = int(max_patches_per_sample * 0.4)
Beispiel #2
0
    def make(self, projectConfig):
        makeConf = {
            'target_type':
            projectConfig.getItem('make.configuration.target.type',
                                  self.defaultConf['target_type']),
            'ar':
            projectConfig.getItem('make.configuration.archiver.ar',
                                  self.defaultConf['ar']),
            'ld':
            projectConfig.getItem('make.configuration.linker.ld',
                                  self.defaultConf['ld']),
            'ldflags':
            projectConfig.getItem('make.configuration.linker.flags',
                                  self.defaultConf['ldflags']),
            'ld_library_paths':
            projectConfig.getItem('make.configuration.linker.library_paths',
                                  self.defaultConf['ld_library_paths']),
            'libraries':
            projectConfig.getItem('make.configuration.linker.libraries', []),
            'solution_dir':
            projectConfig.getItem('global.solution.dir', '..'),
            'sources':
            projectConfig.getItem('make.configuration.linker.include', []),
        }

        makefile = GMakeDocument(TARGET_MAKEFILE_PATH)
        objectSourcePaths = []

        self.objectFiles.clear()
        solutionDirPath = Path(makeConf['solution_dir'], True)
        objectFilePaths = []
        for objectSourcePath in makeConf['sources']:
            objectSourcePath = solutionDirPath.join(objectSourcePath)
            FileUtil.searchAllFiles(objectFilePaths, objectSourcePath, ['.o'])

        for objectFilePath in objectFilePaths:
            self.objectFiles.append(Path(objectFilePath))

        finalFilePath = self.getFinalFilePath(projectConfig, makeConf)
        linkRule = self.getLinkRule(finalFilePath, makeConf)
        subMakefile = GMakeDocument(FINAL_TARGET_SUBMAKE_PATH)
        subMakefile.addRule(linkRule)

        makefile.addSubDocument(subMakefile)

        allRule = GMakeSimpleRule('all', [finalFilePath])
        makefile.addRule(allRule)

        makefile.writeToFile()

        return True
Beispiel #3
0
    def split_edge(self, new_len, child):
        p1 = self.path
        p2 = child.path
        assert len(p1) < new_len < len(p2), "split length %d->%d->%d" % (
            len(p1), new_len, len(p2))
        edge_start = p2.start + len(p1)
        edge_end = p2.start + new_len
        new_node = Internal(self, Path(p2.S, p2.start, edge_end))

        self.children[p2.S[edge_start]] = new_node  # substitute new node
        new_node.children[p2.S[edge_end]] = child
        child.parent = new_node

        return new_node
Beispiel #4
0
import os
import modules.module

from util import Path, PathUtil, FileUtil, Configuration, ConsoleLogger
from backends.gmake.engine import Document as GMakeDocument
from backends.gmake.engine import SimpleRule as GMakeSimpleRule
from backends.gmake.engine import GCCCompileRule
from backends.gmake.engine import GCCLinkRule
from backends.gmake.engine import ArRule

TARGET_PATH = Path('target', True)
TARGET_MAKEFILE_PATH = TARGET_PATH.join('Makefile')
TARGET_SUBMAKE_PATH = TARGET_PATH.join('submake')
FINAL_TARGET_SUBMAKE_PATH = TARGET_SUBMAKE_PATH.join('final_target')


class Module(modules.module.Module):
    objectFiles = []
    defaultConf = {}

    def __init__(self):
        modules.module.Module.__init__(self)
        self.defaultConf['target_type'] = 'executable'
        self.defaultConf['ar'] = 'ar'
        self.defaultConf['ld'] = 'g++'
        self.defaultConf['ldflags'] = ''
        self.defaultConf['ld_library_paths'] = []
        self.logger = ConsoleLogger('ldmodule')

    def initKakefile(self):
        kakefile = FileUtil.openFile('Kakefile')
Beispiel #5
0
    def make(self, projectConfig):
        makeConf = {
            'target_type':
            projectConfig.getItem('make.configuration.target.type',
                                  self.defaultConf['target_type']),
            'cc':
            projectConfig.getItem('make.configuration.compiler.c.cc',
                                  self.defaultConf['cc']),
            'cxxc':
            projectConfig.getItem('make.configuration.compiler.cpp.cc',
                                  self.defaultConf['cxxc']),
            'cflags':
            projectConfig.getItem('make.configuration.compiler.c.flags',
                                  self.defaultConf['cflags']),
            'cxxflags':
            projectConfig.getItem('make.configuration.compiler.cpp.flags',
                                  self.defaultConf['cxxflags']),
            'fpic':
            projectConfig.getItem('make.configuration.compiler.fpic',
                                  self.defaultConf['fpic']),
            'autolink':
            projectConfig.getItem('make.configuration.linker.autolink',
                                  self.defaultConf['autolink']),
            'ar':
            projectConfig.getItem('make.configuration.archiver.ar',
                                  self.defaultConf['ar']),
            'ld':
            projectConfig.getItem('make.configuration.linker.ld',
                                  self.defaultConf['ld']),
            'ldflags':
            projectConfig.getItem('make.configuration.linker.flags',
                                  self.defaultConf['ldflags']),
            'ld_library_paths':
            projectConfig.getItem('make.configuration.linker.library_paths',
                                  self.defaultConf['ld_library_paths']),
            'libraries':
            projectConfig.getItem('make.configuration.linker.libraries', []),
            'c_src_exts':
            projectConfig.getItem('make.configuration.compiler.c.src_exts',
                                  self.defaultConf['c_src_exts']),
            'cxx_src_exts':
            projectConfig.getItem('make.configuration.compiler.cpp.src_exts',
                                  self.defaultConf['cxx_src_exts']),
            'c_include_paths':
            projectConfig.getItem(
                'make.configuration.compiler.c.include_paths',
                self.defaultConf['c_include_paths']),
            'cxx_include_paths':
            projectConfig.getItem(
                'make.configuration.compiler.cpp.include_paths',
                self.defaultConf['cxx_include_paths']),
            'cxx_using_c_include_paths':
            projectConfig.getItem(
                'make.configuration.compiler.cpp.inherit_c_include_path',
                self.defaultConf['cxx_using_c_include_paths'])
        }

        makefile = GMakeDocument(TARGET_MAKEFILE_PATH)

        self.mainSourceFiles.clear()
        self.objectFiles.clear()
        cSourceFiles = []
        cppSourceFiles = []
        FileUtil.searchAllFiles(cSourceFiles, SRC_MAIN_PATH,
                                makeConf['c_src_exts'])
        FileUtil.searchAllFiles(cppSourceFiles, SRC_MAIN_PATH,
                                makeConf['cxx_src_exts'])
        self.mainSourceFiles.extend(cSourceFiles)
        self.mainSourceFiles.extend(cppSourceFiles)

        for fileName in self.mainSourceFiles:
            filePath = Path(fileName, True)
            relPath = filePath.getRelevantPath(SRC_MAIN_PATH)
            dirName = relPath.getDirName()
            baseName = relPath.getBaseName()

            subMakeDirPath = TARGET_SUBMAKE_MAIN_PATH.join(dirName)
            FileUtil.createDirectory(subMakeDirPath)

            subMakefilePath = subMakeDirPath.join(PathUtil.getPrefix(baseName))
            subMakefilePath.appendExt('mk')
            subMakefile = GMakeDocument(subMakefilePath)

            compileRule = GCCCompileRule(filePath, [INCLUDE_MAIN_PATH],
                                         SRC_MAIN_PATH,
                                         TARGET_OBJECT_MAIN_PATH, makeConf)
            subMakefile.addRule(compileRule)
            makefile.addSubDocument(subMakefile)

            objectFilePath = Path(compileRule.getTarget())
            self.objectFiles.append(objectFilePath)

        if makeConf['autolink']:
            if makeConf['target_type'] == 'executable':
                subMakefile = GMakeDocument(FINAL_TARGET_SUBMAKE_PATH)

                finalFileName = '%(name)s-%(version)s' % {
                    'name': projectConfig.getItem('project.name', 'noname'),
                    'version': projectConfig.getItem('project.version',
                                                     '1.0.0')
                }
                finalFilePath = TARGET_PATH.join(finalFileName)

                linkRule = GCCLinkRule(finalFilePath, self.objectFiles,
                                       makeConf)
                subMakefile.addRule(linkRule)

                makefile.addSubDocument(subMakefile)

                allRule = GMakeSimpleRule('all', [finalFilePath])
                makefile.addRule(allRule)
            elif makeConf['target_type'] == 'dynamic_library':
                subMakefile = GMakeDocument(FINAL_TARGET_SUBMAKE_PATH)

                finalFileName = 'lib%(name)s.so.%(version)s' % {
                    'name': projectConfig.getItem('project.name', 'noname'),
                    'version': projectConfig.getItem('project.version',
                                                     '1.0.0')
                }
                finalFilePath = TARGET_PATH.join(finalFileName)

                linkRule = GCCLinkRule(finalFilePath, self.objectFiles,
                                       makeConf)
                subMakefile.addRule(linkRule)

                makefile.addSubDocument(subMakefile)

                allRule = GMakeSimpleRule('all', [finalFilePath])
                makefile.addRule(allRule)
            elif makeConf['target_type'] == 'static_library':
                subMakefile = GMakeDocument(FINAL_TARGET_SUBMAKE_PATH)

                finalFileName = 'lib%(name)s.a.%(version)s' % {
                    'name': projectConfig.getItem('project.name', 'noname'),
                    'version': projectConfig.getItem('project.version',
                                                     '1.0.0')
                }
                finalFilePath = TARGET_PATH.join(finalFileName)

                arRule = ArRule(finalFilePath, self.objectFiles, makeConf)
                subMakefile.addRule(arRule)

                makefile.addSubDocument(subMakefile)

                allRule = GMakeSimpleRule('all', [finalFilePath])
                makefile.addRule(allRule)
            else:
                self.logger.warn('target_type is not recognized!')
                sys.exit(1)
        else:
            allRule = GMakeSimpleRule('all', self.objectFiles)
            makefile.addRule(allRule)

        makefile.writeToFile()

        return True
Beispiel #6
0
import os
import sys
import modules.module

from util import Path, PathUtil, FileUtil, Configuration, ConsoleLogger
from backends.gmake.engine import Document as GMakeDocument
from backends.gmake.engine import SimpleRule as GMakeSimpleRule
from backends.gmake.engine import GCCCompileRule
from backends.gmake.engine import GCCLinkRule
from backends.gmake.engine import ArRule

SRC_PATH = Path('src', True)
INCLUDE_PATH = Path('include', True)
TARGET_PATH = Path('target', True)
SRC_MAIN_PATH = SRC_PATH.join('main')
SRC_TEST_PATH = SRC_PATH.join('test')
INCLUDE_MAIN_PATH = INCLUDE_PATH.join('main')
INCLUDE_TEST_PATH = INCLUDE_PATH.join('test')
TARGET_OBJECT_PATH = TARGET_PATH.join('object')
TARGET_OBJECT_MAIN_PATH = TARGET_OBJECT_PATH.join('main')
TARGET_SUBMAKE_PATH = TARGET_PATH.join('submake')
TARGET_SUBMAKE_MAIN_PATH = TARGET_SUBMAKE_PATH.join('main')
TARGET_MAKEFILE_PATH = TARGET_PATH.join('Makefile')
FINAL_TARGET_SUBMAKE_PATH = TARGET_SUBMAKE_PATH.join('final_target.mk')


class Module(modules.module.Module):
    mainSourceFiles = []
    objectFiles = []
    defaultConf = {}
Beispiel #7
0
    def __init__(
        self,
        contract: IBContract,
        invest: float,
        s_window: int,
        l_window: int,
        update_interval: int = 15,
        band_offset: float = 0.1,
    ) -> None:
        assert (isinstance(contract, IBContract))
        assert (0 < invest if isinstance(invest, float) else False)
        assert (0 < s_window if isinstance(s_window, int) else False)
        assert (0 < l_window if isinstance(l_window, int) else False)
        assert (s_window < l_window)
        assert (15 <= update_interval
                if isinstance(update_interval, int) else False)
        assert (0 < band_offset if isinstance(band_offset, float) else False)

        EClient.__init__(self, self)
        self.connect('127.0.0.1', 7497, 0)

        self.contract = contract
        self.invest = invest
        self.s_window, self.l_window = s_window, l_window
        self.s_alpha, self.l_alpha = 2 / (s_window + 1), 2 / (l_window + 1)
        self.update_interval = update_interval
        self.band_offset = band_offset

        self.odir = Path('sg3tws_out')
        self.rid = itertools.count()
        self.oid = itertools.count(start=1)

        # init market data subscription
        self.data = {
            'DELAYED_ASK': 0,
            'DELAYED_BID': 0,
            'DELAYED_ASK_SIZE': 0,
            'DELAYED_BID_SIZE': 0,
            'DELAYED_VOLUME': 0,
            'DELAYED_LAST': 0,
            'DELAYED_LAST_SIZE': 0,
            'DELAYED_HIGH': 0,
            'DELAYED_LOW': 0,
            'DELAYED_CLOSE': 0,
            'DELAYED_OPEN': 0
        }

        self.df_data = pd.DataFrame(columns=list(self.data.keys()))
        self.df_data.index.name = 'time'
        self.data_file = self.odir.join('data.csv')
        self.df_data.to_csv(self.data_file)

        self.reqMarketDataType(3)
        self.reqMktData(next(self.rid), self.contract, '', False, False, [])

        # init account data subscription
        self.account = {'TotalCashValue': 0., 'GrossPositionValue': 0.}
        self.df_account = pd.DataFrame(columns=list(self.account.keys()))
        self.df_account.index.name = 'time'
        self.account_file = self.odir.join('account.csv')
        self.df_account.to_csv(self.account_file)
        self.reqAccountSummary(next(self.rid), 'All',
                               ', '.join(self.account.keys()))

        # init trades log
        self.n_order = itertools.count(1)
        self.orders = {
            'time': datetime.datetime.now(),
            'oid': 0,
            'shares': 0,
            'avg_price': 0.,
            'tick_price': 0.,
            'commission': 0.,
            'total': 0.,
            'exchange': ''
        }
        self.df_orders = pd.DataFrame(columns=list(self.orders.keys()))
        self.df_orders.index.name = 'n'
        self.orders_file = self.odir.join('orders.csv')
        self.df_orders.to_csv(self.orders_file)

        # init technical analysis
        self.fields = [
            'price', 'mal', 'mas', 'mao', 'ub', 'lb', 'cash', 'stock', 'pos',
            'total hold', 'total'
        ]
        self.stat = dict(
            zip(self.fields, np.zeros_like(self.fields, dtype=np.float)))

        self.df_stat = pd.DataFrame(columns=self.fields)
        self.df_stat.index.name = 'time'
        self.stat_file = self.odir.join('stat.csv')
        self.df_stat.to_csv(self.stat_file)

        # init plotting
        register_matplotlib_converters()
        self.fig, self.axes = plt.subplots(nrows=4, sharex='all')
        self.fig.set(figwidth=10, figheight=9)
        self.axes[0].set_title('SG3TWS {}'.format(self.contract.symbol),
                               fontsize=18)
        self.axes[0].set_ylabel('Price', fontsize=14)
        self.axes[1].set_ylabel('Oscillator', fontsize=14)
        self.axes[1].axhline(y=0, ls='-', c='k')
        self.axes[2].set_ylabel('Position', fontsize=14)
        self.axes[3].set_ylabel('Portfolio value', fontsize=14)
        self.axes[3].set_xlabel('Time', fontsize=14)
        self.lines = {
            'price': self.axes[0].plot([], [], label='price')[0],
            'mas': self.axes[0].plot([], [], label='mas')[0],
            'mal': self.axes[0].plot([], [], label='mal')[0],
            'mao': self.axes[1].plot([], [], label='mao')[0],
            'ub': self.axes[1].plot([], [], '--k', label='ub')[0],
            'lb': self.axes[1].plot([], [], '--k', label='lb')[0],
            'pos': self.axes[2].plot([], [], label='position')[0],
            'total hold': self.axes[3].plot([], [], label='total hold')[0],
            'total': self.axes[3].plot([], [], label='total')[0],
        }
        for ax in self.axes:
            ax.legend()
        self.fig.tight_layout()

        # initiate TWS-API loop and strategy loop
        threading.Thread(target=self.run, args=()).start()
        threading.Thread(target=self.exec, args=()).start()
Beispiel #8
0
import os
import sys
import modules.module

from util import Path, PathUtil, FileUtil, Configuration, ConsoleLogger
from backends.gmake.engine import Document as GMakeDocument
from backends.gmake.engine import SimpleRule as GMakeSimpleRule
from backends.gmake.engine import GCCCompileRule
from backends.gmake.engine import GCCLinkRule
from backends.gmake.engine import ArRule

PROJECT_PATH = Path('project', True)
TARGET_PATH = Path('target', True)

class Module(modules.module.Module):
    defaultConf = {}
    projects = []

    def __init__(self):
        #'solution_dir': projectConfig.getItem('global.solution.dir', '..'),
        self.logger = ConsoleLogger('cmodule')

        projectNames = os.listdir('project')
        projectNames.sort()
        for projectName in projectNames:
            project = {
                'name': projectName,
                'path': PROJECT_PATH.join(projectName)
            }
            self.projects.append(project)