How to use the namedlist.namedlist function in namedlist

To help you get started, we’ve selected a few namedlist examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github niksaz / dota2-expert-demo / deepq / dqn.py View on Github external
import numpy as np
import tensorflow as tf
from namedlist import namedlist

sys.path.append('../')

from deepq import ReplayRewardShaper, Estimator, StatePreprocessor, persistence
from dotaenv import DotaEnvironment
from dotaenv.codes import ATTACK_TOWER, STATE_DIM

STATE_SPACE = STATE_DIM
ACTION_SPACE = ATTACK_TOWER + 1
MAX_PRIORITY = 10
EPS_PRIORITY = 1e-9

Transition = namedlist(
    'Transition',
    ['state', 'action', 'next_state', 'done', 'reward', 'priority'])


class PrioritizedReplayBuffer:
    """Reference paper: https://arxiv.org/pdf/1511.05952.pdf.
    """

    def __init__(self, replay_memory_size, alpha, beta0, reward_shaper, discount_factor, save_dir):
        """Initializes the replay buffer and caps the memory size to replay_memory_size.
        """
        self.replay_memory = deque(maxlen=replay_memory_size)
        self.alpha = alpha
        self.beta0 = beta0
        self.reward_shaper = reward_shaper
        self.discount_factor = discount_factor
github HanGuo97 / tf-library / TFLibrary / DDPG / ddpg.py View on Github external
from tensorflow.python.ops import math_ops
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import nn_ops

from tensorflow.python.ops import variables
from tensorflow.python.ops import gradients_impl
from tensorflow.python.training import adam as adam_ops
from tensorflow.python.training import gradient_descent as gd_ops
from tensorflow.python.ops import variable_scope as vs

from tensorflow.python.framework import dtypes
from tensorflow.contrib import layers as contrib_layers


Experience = namedlist("Experience",
    ("State", "Action", "Reward", "NextState"))


class SingleEpisodeDDPGController(object):
    def __init__(self,
                 sess,
                 num_units,
                 num_actions,
                 batch_size,
                 learning_rate,
                 tau,
                 gamma,
                 actor_activation=math_ops.sigmoid,
                 critic_activation=None,
                 opitmizer_name="adam",
                 max_gradient_norm=5.0,
github Coldcard / firmware / stm32 / bootloader / secel_config.py View on Github external
def make_bitmask(name, defs):
        '''
            Name a list of bit widths and names, and convert into a class.
        '''
        rv = namedlist(name, (n for w,n in defs), default=0)

        assert sum(w for w,n in defs) == 16

        @classmethod
        def unpack(cls, ss):
            v = struct.unpack("> pos) & ((1<
github antevens / cerlet / cerlet / __init__.py View on Github external
the CA has told it when to try again), output a delay size in seconds, a
            newline, and a "cookie" value, and exit with status 5.  The daemon will try
            again after the specified amount of time has passed.

        * If the CA indicates that the client needs to try again using a different
            key pair in the signing request (for example, if its policy limits the
            number of times a particular key pair can be enrolled, or the length of
            time one can be in service), exit with status 17.  The daemon will generate
            a new key pair and try again.

        * If the helper does not understand what is being asked of it, exit with
            status 6.  You should never return this value for "SUBMIT" or "POLL", but
            it is mentioned here so that we can refer to this list later.
        """
        logger.debug('Submitting certificate signing request')
        CSR = namedlist.namedlist('CSR', 'data form')
        csr = CSR(data = csr or self.environment['CERTMONGER_CSR'], form='pem')
        domains = domains or [self.environment['CERTMONGER_REQ_SUBJECT']]

        try:
            cert, chain = self.client.obtain_certificate_from_csr(domains, csr)
            sys.stdout.write(OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_PEM, cert.body))
            return self.EXIT_ISSUED

        except acme.messages.Error as e:
            logger.error(e)
            sys.stdout.write(str(e))
            return self.EXIT_REJECTED

        except acme.error.ClientError as e:
            logger.error(e)
            sys.stdout.write(str(e))
github ARTFL-Project / text-pair / lib / textpair / compare_ngrams.py View on Github external
from multiprocess import Pool

from namedlist import namedlist

docIndex = namedlist("docIndex", "doc_id, ngrams, ngram_length")
indexedNgram = namedlist("indexedNgram", "n_index, start_byte, end_byte")
ngramMatch = namedlist("ngramMatch", "source target ngram")
matchingParams = namedlist(
    "matchingParams",
    """matching_window_size, max_gap, flex_gap, minimum_matching_ngrams, minimum_matching_ngrams_in_window,
    common_ngrams_limit, minimum_matching_ngrams_in_docs, context_size, banal_ngrams, merge_on_byte_distance,
    merge_on_ngram_distance, passage_distance_multiplier, duplicate_threshold, source_batch, target_batch,
    output_path, num_workers, sorting_field, debug""",
)
position = namedlist("position", [("start_byte", 0), ("end_byte", 0), ("start_ngram_index", 0), ("end_ngram_index", 0)])
Alignment = namedlist(
    "Alignment", [("source", position()), ("target", position()), ("total_matching_ngrams", 0), ("banality", False)]
)
matchValues = namedlist(
    "matchValues",
    [
        ("in_alignment", False),
        ("matches_in_current_alignment", 0),
        ("matches_in_current_window", 0),
        ("source_anchor", 0),
        ("last_source_position", 0),
        ("target_anchor", 0),
        ("last_target_position", 0),
        ("previous_source_index", 0),
        ("common_ngram_matches", 0),
        ("max_source_gap", 0),
        ("max_target_gap", 0),
github antevens / cerlet / cerlet / __init__.py View on Github external
# Set User Agent
        self.defaults['user_agent'] = user_agent

        # Override account directory
        self.defaults['accounts_dir'] = os.path.join(paths['config_dir'],
                                                     certbot.constants.ACCOUNTS_DIR,
                                                     self.environment['CERTMONGER_REQ_HOSTNAME'])

        # Create any directories which don't exist with correct
        # permisisons/owner/group and set in config
        for key, path in paths.iteritems():
            mkdirp(path, permission_mode=0o700)
            self.defaults[key] = path

        # Create config object from defaults in certbot and assign defaults
        Config = namedlist.namedlist('Config', ' '.join(self.defaults.keys()))
        self.namespace = Config(**self.defaults)
        self.config = certbot.configuration.NamespaceConfig(namespace=self.namespace)
        zope.component.provideUtility(self.config)

        # Configure displayer depending on if we have a tty or not
        if sys.stdout.isatty():
            self.displayer = certbot.display.util.NoninteractiveDisplay(sys.stdout)
        else:
            self.displayer = certbot.display.util.NoninteractiveDisplay(open(os.devnull, "w"))

        zope.component.provideUtility(self.displayer)

        # Set up Certbot Account Storage, at some point this should be moved
        # and stored by IPA in LDAP. For now we create separate accounts per
        # host and store details on the filesystem.
        account_storage = certbot.account.AccountFileStorage(self.config)
github ARTFL-Project / text-pair / lib / textpair / compare_ngrams.py View on Github external
("last_target_position", 0),
        ("previous_source_index", 0),
        ("common_ngram_matches", 0),
        ("max_source_gap", 0),
        ("max_target_gap", 0),
        ("source_window_boundary", 0),
        ("target_window_boundary", 0),
        ("current_alignment", Alignment()),
        ("previous_alignment", None),
        ("first_match", None),
        ("last_match", None),
        ("debug", False),
    ],
)
alignmentsPerDoc = namedlist("alignmentsPerDoc", "doc_id, matches, duplicates")
CombinedAlignments = namedlist("CombinedAlignments", "source_id, alignments")


class compareNgrams:
    def __init__(
        self,
        source_files,
        source_metadata,
        target_files=None,
        target_metadata=None,
        output_path="./output",
        workers=4,
        sort_field="year",
        source_batch=1,
        target_batch=1,
        source_common_ngrams=None,
        target_common_ngrams=None,
github ARTFL-Project / text-pair / lib / textpair / vector_similarity.py View on Github external
from dill import load, dump
import numpy as np
from gensim.corpora.dictionary import Dictionary
from gensim.corpora.textcorpus import TextCorpus
from gensim.models import TfidfModel
from gensim.models.phrases import Phraser, Phrases
from gensim.similarities import LevenshteinSimilarityIndex
from gensim.similarities.docsim import SparseMatrixSimilarity, MatrixSimilarity
from gensim.models.doc2vec import Doc2Vec, TaggedDocument
from namedlist import namedlist
from text_preprocessing import PreProcessor, Token, Tokens
from tqdm import tqdm

TAGS = re.compile(r"<[^>]+>")

PASSAGE_GROUP = namedlist(
    "PassageGroup", [("vector", []), ("start_byte", 0), ("end_byte", 0), ("filename", None), ("metadata", {})]
)
MERGED_GROUP = namedlist("MergedGroup", [("source", PASSAGE_GROUP()), ("target", PASSAGE_GROUP()), ("similarity", 0.0)])

PHILO_TEXT_OBJECT_LEVELS = {"doc": 1, "div1": 2, "div2": 3, "div3": 4, "para": 5, "sent": 6, "word": 7}

TEMP_DIR = os.getcwd()


def fast_cosine(X, Y):
    return np.inner(X, Y) / np.sqrt(np.dot(X, X) * np.dot(Y, Y))


class CorpusLoader(TextCorpus):
    """Base class for linking gensim's TextCorpus and the text-preprocessing output"""
github matcom / autoexam / qtui / model.py View on Github external
- tag_names
- text
- answers

Answer:
- valid
- fixed_position
- text
"""

import json
from namedlist import namedlist

# Project = namedlist('Project', ['name', 'total_questions_per_exam', 'total_exams_to_generate', 'current_page', 'tags', 'questions'])
Project = namedlist('Project', ['name', 'total_questions_per_exam', 'total_exams_to_generate', 'tags', 'questions'])
Tag = namedlist('Tag', ['name', 'min_questions'])
Question = namedlist('Question', ['id', 'tag_names', 'text', 'answers'])
Answer = namedlist('Answer', ['valid', 'fixed_position', 'text'])


def dump_project(proj, path):
    try:
        s = json.dumps(proj)
        with open(path, 'w') as fp:
            fp.write(s)
    except:
        print 'Error saving Project'


def load_project(path):
    with open(path, 'r') as fp:
        proj = json.load(fp)
github olinrobotics / irl / dino_arms / projects / actuation / ur5_arm_node.py View on Github external
import urx

"""
Wrapper for UR5 robotic arm
Direct requests to the UR5 arm should be sent through this node

Arm can be used via joints(ROS) or via XYZ coordinates(TCP)

Note: if scripts or arm ever time out or freeze up, then just restart scripts and restart
the arm. It's just that there might be big load on the TCP/ROS connections,

Before this, the UR driver needs to be brought online:
rosrun ur_modern_driver ur5_bringup.launch robot_ip:=10.42.0.175
"""

Route = namedlist('Route', 'joints duration')

def rad2pi(joint_states):
    """control tablet reads in joint positions in degrees
    JointTrajectoryPoint is in radians. we can define as either, but this will convert to radians"""
    return [(j*pi/180) for j in joint_states]

class Arm():
    def __init__(self):
        #Setting up the connection to UR5 server
        rospy.init_node("arm_node", anonymous=True, disable_signals=True)
        self.client = actionlib.SimpleActionClient('follow_joint_trajectory', FollowJointTrajectoryAction)
        print "Waiting for server..."
        self.client.wait_for_server()
        print "Connected to server"

        self.JOINT_NAMES = ['shoulder_pan_joint', 'shoulder_lift_joint', 'elbow_joint',

namedlist

Similar to namedtuple, but instances are mutable.

Apache-2.0
Latest version published 4 years ago

Package Health Score

46 / 100
Full package analysis

Similar packages