Entry point function for analysis based on parameter files.

    Parameters
    ----------
    param_path : str
        Path to user-generated parameter file
423043
def main(param_path='parameters.txt'):
    

    # Confirm parameters file is present
    if not os.path.isfile(param_path):
        raise IOError, "Parameter file not found at %s" % param_path

    # Get raw params and base options (non-run-dependent options)
    params, base_options = _get_params_base_options(param_path)

    # Configure and start logging
    # Done here instead of in function so will affect all subsequent calls
    log_path = os.path.join(base_options['results_dir'], '_log.txt')
    if os.path.isfile(log_path):
        os.remove(log_path)

    logging.basicConfig(level=logging.INFO, format='%(message)s')

    fileh = logging.FileHandler(log_path)
    fileh.setLevel(logging.DEBUG)
    filefmt = logging.Formatter(
            time.strftime("%Y/%m/%d %H:%M:%S %p", time.localtime()) + 
            ' - %(name)s - %(levelname)s - %(message)s')
    fileh.setFormatter(filefmt)
    logging.getLogger('').addHandler(fileh)

    def log_uncaught(type1, value1, traceback1):
        tb_list = traceback.format_exception(type1, value1, traceback1)
        tb_str = ''.join(tb_list)
        logging.critical('\n\n'+tb_str)
    sys.excepthook = log_uncaught

    logging.info('Running macroeco') # v%s' % __version__)
    logging.info('Parameters file at %s' % os.path.abspath(param_path))

    # Preliminary check for errors in parameters file
    bad_params = misc.check_parameter_file(param_path)
    if len(bad_params[0]) > 0:
        logging.warning("Possible formatting error(s) in" +
                    " %s: parameters %s on lines %s"
                      % (param_path, bad_params[0], bad_params[1]))

    logging.info('Starting analysis')

    # Do analysis for each run
    for run_name in base_options['run_names']:
        logging.info('Starting run %s' % run_name)
        options = dict(params[run_name])  # All parameters from this run
        options.update(base_options)  # Add base parameters
        options['run_dir'] = os.path.join(base_options['results_dir'],run_name)
        if 'format' in options['analysis']:
            _do_format(options)
        else:
            _do_analysis(options)
        logging.info('Finished run %s' % run_name)
    logging.info('Finished analysis successfully')
    logging.info('Results available at %s' % options['param_dir'])

    # Close logging - releases log file lock in Windows GUI
    logging.shutdown()
145759
def main():
    
    setup_main_logger(file_logging=False)
    params = argparse.ArgumentParser(description='Shows nearest neighbours of input tokens in the embedding space.')
    params.add_argument('--model', '-m', required=True,
                        help='Model folder to load config from.')
    params.add_argument('--checkpoint', '-c', required=False, type=int, default=None,
                        help='Optional specific checkpoint to load parameters from. Best params otherwise.')
    params.add_argument('--side', '-s', required=True, choices=['source', 'target'], help='what embeddings to look at')
    params.add_argument('--norm', '-n', action='store_true', help='normalize embeddings to unit length')
    params.add_argument('-k', type=int, default=5, help='Number of neighbours to print')
    params.add_argument('--gamma', '-g', type=float, default=1.0, help='Softmax distribution steepness.')
    args = params.parse_args()
    embeddings(args)
1079831
def load(cls, file_path):
        

        # convert back to numpy
        data = helper.read_json(file_path)
        return Concise.from_dict(data)
167067
def import_parameters_from_file(parameters_file):
    
    params = {}

    with open(parameters_file, 'r') as f:
        matches = re.findall('(.*): (.*)', f.read())

    for m in matches:
        params[m[0]] = ast.literal_eval(m[1])

    return params
803683
def analyse_source(pPath)
        @name = File.basename(pPath, ".*")
        @path = File.dirname(pPath)
        analyse_first_step(pPath)
        analyse_second_step
      end
305478
def log_analyzer(path):
    
    with handle(MalformedLogEntryError,
                  lambda (c):
                      invoke_restart('use_value',
                                     MalformedLogEntry(c.text))):
        for filename in find_all_logs(path):
            analyze_log(filename)
982617
static List<MethodParameter> extract(String path) {

		List<MethodParameter> output = new ArrayList<>();

		List<String> items = split(path);

		if (items.size() > 0) {

			int pathIndex = 0;
			int index = 0;
			for (String item : items) {

				MethodParameter param = getParamFromPath(item, index, pathIndex); // set negative index until confirmed that needed

				if (param != null) {
					output.add(param);
					index++;
				}

				pathIndex++;
			}
		}

		return output;
	}
467214
def relpath(path, start=posixpath.curdir):
    """"""
    if not path:
        raise ValueError("no path specified")

    start_list = posixpath.abspath(start).split(posixpath.sep)
    path_list = posixpath.abspath(path).split(posixpath.sep)

    # Work out how much of the filepath is shared by start and path.
    i = len(posixpath.commonprefix([start_list, path_list]))

    rel_list = [posixpath.pardir] * (len(start_list) - i) + path_list[i:]
    if not rel_list:
        return posixpath.curdir
    return posixpath.join(*rel_list)
1299353
def mkdir_p(self, path):
        
        try:
            if not os.path.isdir(path):
                os.makedirs(path)
                self.log.info('Created Directory [ %s ]', path)
        except OSError as exc:
            if exc.errno == errno.EEXIST and os.path.isdir(path):
                pass
            else:
                raise OSError(
                    'The provided path can not be created into a directory.'
                )
1056353
def path(self, args, kw):
        """"""
        params = self._pop_params(args, kw)
        if args or kw:
            raise InvalidArgumentError("Extra parameters (%s, %s) when building path for %s" % (args, kw, self.template))
        return self.build_url(**params)
112613
def reader_from_path(cls, path):
        
        context = FilePathContext(path)
        try:
            with open(context.filepath, 'r') as f:
                return ModelReader(f, context)
        except IOError:
            # Try to open the default file
            for filename in cls.DEFAULT_MODEL:
                try:
                    context = FilePathContext(
                        os.path.join(path, filename))
                    with open(context.filepath, 'r') as f:
                        return ModelReader(f, context)
                except:
                    logger.debug('Failed to load model file',
                                 exc_info=True)

        # No model could be loaded
        raise ParseError('No model file could be found ({})'.format(
            ', '.join(cls.DEFAULT_MODEL)))
1283899
def load(self, path):
        
        config = _Config.load(os.path.join(path, 'config.pkl'))
        config.save_dir = path  # redirect root path to what user specified
        self._vocab = vocab = ParserVocabulary.load(config.save_vocab_path)
        with mx.Context(mxnet_prefer_gpu()):
            self._parser = BiaffineParser(vocab, config.word_dims, config.tag_dims, config.dropout_emb,
                                          config.lstm_layers,
                                          config.lstm_hiddens, config.dropout_lstm_input, config.dropout_lstm_hidden,
                                          config.mlp_arc_size,
                                          config.mlp_rel_size, config.dropout_mlp, config.debug)
            self._parser.load(config.save_model_path)
        return self
118910
def validate_path_parameters(target_path, api_path, path_parameters, context):
    
    base_path = context.get('basePath', '')
    full_api_path = re.sub(NORMALIZE_SLASH_REGEX, '/', base_path + api_path)
    parameter_values = get_path_parameter_values(
        target_path, full_api_path, path_parameters, context,
    )
    validate_parameters(parameter_values, path_parameters, context=context)
413217
def runpath(path, argv, filename=None, threads=True, verbose=False):
    
    _run(threads, verbose, 'runpath', filename, path, argv)
847264
def rel_path(*file_path):
        '''
        
        '''
        if hasattr(sys, 'frozen'):
            if file_path[0] == '__file__':
                return sys.executable
            return os.path.join(os.path.dirname(sys.executable), *file_path)
        else:
            try:
                main_file = AppBuilder.main_file
            except AttributeError:
                # The first call setting up the instance
                main_file = inspect.stack()[1][1]
            if file_path[0] == '__file__':
                return os.path.realpath(main_file)
            return os.path.join(os.path.dirname(main_file), *file_path)
230844
def load_params(filepath):
    
    # Read the file
    with open(filepath) as file:
        content = file.read()

    # Detect all environment variables referenced (using %EXAMPLE%, use windows style since it is easier to match)
    q = [m.start() for m in re.finditer("%", content)]
    env_vars = []
    for i in range(0, len(q), 2):
        env_var = content[q[i]+1:q[i+1]]
        if env_var not in env_vars:
            if env_var in os.environ:
                env_vars.append(env_var)
            else:
                print("WARNING: Detected an environment variable which is not set.")
    
    # Fill in environment variables
    for env_var in env_vars:
        s = "%" + env_var + "%"
        # Use unix style path linebreaks, since windows style might break stuff (and linux is more common anyways.)
        content = content.replace(s, os.environ[env_var].replace("\\", "/"))

    # Try to match linux path style with anything that matches
    for env_var in list(os.environ.keys()):
        s = "$" + env_var
        content = content.replace(s, os.environ[env_var].replace("\\", "/"))

    # Finally load hyperparams
    return HyperParams(json.loads(jsmin(content)))
399945
def load_parameters(self, path_to_yaml_dir):
        

        parameters = ParameterNode('', directory_path = path_to_yaml_dir)

        if self.preprocess_parameters is not None:
            parameters = self.preprocess_parameters(parameters)

        self.parameters = parameters