How to use _representation method in autotest

Best Python code snippet using autotest_python

ant.py

Source:ant.py Github

copy

Full Screen

1from random import random2import numpy3from copy import deepcopy4from texttable import Texttable5class Ant:6 def __init__(self, size):7 self._size = size8 self._representation = [[] for i in range(size * 2)]9 self._graph = [self._representation]10 self._freeSpots = size - 111 def getFreeSpotsCount(self):12 return self._freeSpots13 def getRepresentation(self):14 return self._representation15 def getGraph(self):16 return self._graph[:]17 def setRepresentation(self, newRepresentation):18 if len(self._representation[-1]) > len(newRepresentation[-1]):19 self.decreaseFreeSpots()20 self._representation = deepcopy(newRepresentation)21 def decreaseFreeSpots(self):22 self._freeSpots -= 123 def nextPossibilities(self):24 possibilities = []25 for i in range(self._size * 2 * (self._freeSpots)):26 newPossibility = deepcopy(self._representation)27 for row in range(self._size * 2):28 possibleNumbers = [i for i in range(1, self._size + 1)]29 for elem in self._representation[row]:30 possibleNumbers.remove(elem)31 # if row >= self._size and newPossibility[row - self._size][-1] in possibleNumbers:32 # possibleNumbers.remove(newPossibility[row - self._size][-1])33 choice = numpy.random.choice(possibleNumbers)34 newPossibility[row].append(choice)35 possibleNumbers.remove(choice)36 possibilities.append(newPossibility)37 return possibilities38 def move(self, q0, trace, alpha, beta):39 nextPossibilities = self.nextPossibilities()40 distances = []41 if len(nextPossibilities) == 0:42 return False43 auxAnt = Ant(self._size)44 for position in nextPossibilities:45 auxAnt.setRepresentation(position)46 distances.append([position, auxAnt.fitness() - self.fitness()])47 for i in range(len(distances)):48 index = [0, False]49 while index[0] < len(trace) or index[1]:50 if trace[index[0]] == distances[i][0]:51 index[1] = True52 index[0] += 153 if index[1]:54 distances[i][1] = (distances[i][1] ** beta) * (trace(index[0]) ** alpha)55 if numpy.random.random() < q0:56 distances = min(distances, key=lambda elem:elem[1])57 self.setRepresentation(distances[0])58 self._graph.append(self._representation)59 else:60 suma = 061 for elem in distances:62 suma += elem[1]63 if suma == 0:64 choice = numpy.random.randint(0, len(distances))65 self.setRepresentation(distances[choice][0])66 self._graph.append(self._representation)67 return68 distances = [[distances[i][0], distances[i][1] / suma] for i in range(len(distances))]69 for i in range(len(distances)):70 sum = 071 for j in range(i+1):72 sum += distances[j][1]73 distances[i][1] = sum74 choice = numpy.random.random()75 i = 076 while choice > distances[i][1]:77 i += 178 self.setRepresentation(distances[i][0])79 self._graph.append(self._representation)80 return True81 def __str__(self):82 table = Texttable()83 for i in range(self._size):84 row = []85 for j in range(len(self._representation[i])):86 row.append((self._representation[i][j], self._representation[i + self._size][j]))87 table.add_row(row)88 return table.draw()89 def fitness(self):90 fitness = 091 for i in range(self._size):92 for j in range(len(self._representation[i])):93 if self._representation[i][j] == self._representation[i + self._size][j]:94 fitness += 195 if i < len(self._representation[i]) and self._representation[j][i] == self._representation[j + self._size][i]:96 fitness += 197 for i in range(self._size - 1):98 for j in range(i + 1, self._size):99 fitness += numpy.count_nonzero(100 numpy.equal(self._representation[i + self._size], self._representation[j + self._size]))101 fitness += numpy.count_nonzero(numpy.equal(self._representation[i], self._representation[j]))102 for i in range(len(self._representation[-1]) - 1):103 column11 = [self._representation[j][i] for j in range(self._size)]104 column12 = [self._representation[j + self._size][i] for j in range(self._size)]105 for j in range(i + 1, len(self._representation[i])):106 column21 = [self._representation[k][j] for k in range(self._size)]107 column22 = [self._representation[k + self._size][j] for k in range(self._size)]108 fitness += numpy.count_nonzero(numpy.equal(column11, column21))109 fitness += numpy.count_nonzero(numpy.equal(column12, column22))...

Full Screen

Full Screen

containers.py

Source:containers.py Github

copy

Full Screen

1from typing import Iterable, Any2from .errors import StackEmptyException, QueueEmptyException3__all__ = [4 "Queue", "Stack"5]6def foreach(function, iterable: Iterable):7 for element in iterable:8 function(element)9class Queue(list):10 def __init__(self, _: Iterable = []):11 super(Queue, self).__init__(_)12 self._representation = []13 def __getattribute__(self, name):14 if name in ['append', 'index', 'remove']:15 raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'")16 return super(list, self).__getattribute__(name)17 def foreach(self, function):18 foreach(function, self)19 def enqueue(self, item: Any):20 """Add an item to the beginning of the queue."""21 self.insert(0, item)22 self._representation.insert(0, item)23 return self24 def dequeue(self):25 """Removes the topmost item in the queue and returns it."""26 if(len(self) == 0 or len(self._representation) == 0):27 raise QueueEmptyException28 self._representation.pop(len(self) - 1)29 return self.pop(len(self) - 1)30 def peek(self):31 """Returns the topmost item in the queue without removing it."""32 if(len(self) == 0):33 raise QueueEmptyException34 return self[len(self) - 1]35 @property36 def empty(self):37 """A boolean property indicating whether the queue is empty or not."""38 return len(self) == 039 def __iter__(self):40 for i in self.__reversed__():41 yield i42 def extend(self, iterable: Iterable):43 for i in iterable:44 self.enqueue(i)45 def __str__(self):46 return f"<Queue {self._representation}>"47 @classmethod48 def from_dict(cls):49 pass50class Stack(list):51 def __init__(self, _: Iterable = []):52 super(Stack, self).__init__(_)53 self._representation = _54 def __getattribute__(self, name):55 if name in ['append', 'index', 'remove']:56 raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'")57 return super(list, self).__getattribute__(name)58 def foreach(self, function):59 foreach(function, self)60 def push(self, item: Any):61 """Add an item to the end of the stack."""62 self.insert(len(self), item)63 self._representation.append(item)64 return self65 def pop(self):66 """Removes the last added item in the list and returns it."""67 if(len(self) == 0 or len(self._representation) == 0):68 raise StackEmptyException69 self._representation.pop(len(self) - 1)70 return self.pop(len(self) - 1)71 def peek(self):72 """Returns the topmost item in the stack without removing it."""73 if(len(self) == 0):74 raise StackEmptyException75 return self[len(self) - 1]76 @property77 def empty(self):78 """A boolean property indicating whether the stack is empty or not."""79 return len(self) == 080 def search(self, o: Any) -> int:81 """Returns the 1-based position where an object is on this stack. If the object o occurs as an item in this stack, this method returns the distance from the top of the stack of the occurrence nearest the top of the stack; the topmost item on the stack is considered to be at distance 1. The equals method is used to compare o to the items in this stack."""82 index = 083 for i in self.__reversed__():84 index += 185 if o == i:86 return index87 return -188 def __iter__(self):89 for i in self.__reversed__():90 yield i91 def __str__(self):92 return f"<Stack {self._representation}>"93 def extend(self, iterable: Iterable):94 for i in iterable:...

Full Screen

Full Screen

representers.py

Source:representers.py Github

copy

Full Screen

1import numpy as np2from gep_utils import *3class CheetahRepresenter():4 def __init__(self):5 self._description = ['mean_vx', 'min_z']6 # define goal space7 self._initial_space = np.array([[-4, 7],[-3,2]])8 self._representation = None9 def represent(self, obs_seq, act_seq=None):10 obs = np.copy(obs_seq)11 mean_vx = np.array([obs[0, 8, :].mean()])12 min_z = np.array([obs[0, 0, :].min()])13 self._representation = np.concatenate([mean_vx, min_z], axis=0)14 # scale representation to [-1,1]^N15 self._representation = scale_vec(self._representation, self._initial_space)16 self._representation.reshape(1, -1)17 return self._representation18 @property19 def initial_space(self):20 return self._initial_space21 @property22 def dim(self):23 return self._initial_space.shape[0]24class CMCRepresenter():25 def __init__(self):26 self._description = ['max position', 'range position', 'spent energy']27 # define goal space28 self._initial_space= np.array([[-0.6, 0.6], [0., 1.8], [0, 100]]) # space in which goal are sampled29 self._representation = None30 def represent(self, obs_seq, act_seq):31 spent_energy = np.array([np.sum(act_seq[0, 0, np.argwhere(~np.isnan(act_seq))] ** 2 * 0.1)])32 diff = np.array([np.nanmax(obs_seq[0, 0, :]) - np.nanmin(obs_seq[0, 0, :])])33 max = np.array([np.nanmax(obs_seq[0, 0, :])])34 self._representation = np.concatenate([max, diff, spent_energy], axis=0)35 # scale representation to [-1,1]^N36 self._representation = scale_vec(self._representation, self._initial_space)37 self._representation.reshape(1, -1)38 return self._representation39 @property40 def initial_space(self):41 return self._initial_space42 @property43 def dim(self):...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run autotest automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful