Python math.abs() Examples

The following are 6 code examples for showing how to use math.abs(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module math , or try the search function .

Example 1
Project: VerifAI   Author: BerkeleyLearnVerify   File: features.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def distance(self, pointA, pointB):
        return math.abs(pointA - pointB) 
Example 2
Project: VerifAI   Author: BerkeleyLearnVerify   File: features.py    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def distance(self, pointA, pointB):
        return math.abs(pointA - pointB) 
Example 3
Project: DeepPavlov   Author: deepmipt   File: network.py    License: Apache License 2.0 5 votes vote down vote up
def load_params(self):
        path = str(self.load_path.with_suffix('.json').resolve())
        log.info('[loading parameters from {}]'.format(path))
        with open(path, 'r', encoding='utf8') as fp:
            params = json.load(fp)
        for p in self.GRAPH_PARAMS:
            if self.opt.get(p) != params.get(p):
                if p in ('kb_embedding_control_sum') and \
                        (math.abs(self.opt.get(p, 0.) - params.get(p, 0.)) < 1e-3):
                    continue
                raise ConfigError("`{}` parameter must be equal to saved model"
                                  " parameter value `{}`, but is equal to `{}`"
                                  .format(p, params.get(p), self.opt.get(p))) 
Example 4
Project: insightface   Author: deepinsight   File: data.py    License: MIT License 4 votes vote down vote up
def next_sample(self):
        """Helper function for reading in next sample."""
        #set total batch size, for example, 1800, and maximum size for each people, for example 45
        if self.seq is not None:
          while True:
            if self.cur >= len(self.seq):
                raise StopIteration
            idx = self.seq[self.cur]
            self.cur += 1
            if self.imgrec is not None:
              s = self.imgrec.read_idx(idx)
              header, img = recordio.unpack(s)
              label = header.label
              if self.output_c2c:
                count = self.idx2flag[idx]
                if self.output_c2c==1:
                  v = np.random.uniform(0.4, 0.5)
                elif self.output_c2c==2:
                  v = np.random.uniform(0.4, 0.5)
                  if count>=self.output_c2c:
                    v = np.random.uniform(0.3, 0.4)
                elif self.output_c2c==3:
                  v = (9.5 - math.log(2.0+count))/10.0
                  v = min(max(v, 0.3), 0.5)
                elif self.output_c2c==4:
                  mu = 0.0
                  sigma = 0.1
                  mrange = [0.4,0.5]
                  v = numpy.random.normal(mu, sigma)
                  v = math.abs(v)*-1.0+mrange[1]
                  v = max(v, mrange[0])
                elif self.output_c2c==5:
                  v = np.random.uniform(0.41, 0.51)
                  if count>=175:
                    v = np.random.uniform(0.37, 0.47)
                elif self.output_c2c==6:
                  v = np.random.uniform(0.41, 0.51)
                  if count>=175:
                    v = np.random.uniform(0.38, 0.48)
                else:
                  assert False

                label = [label, v]
              else:
                if not isinstance(label, numbers.Number):
                  label = label[0]
              return label, img, None, None
            else:
              label, fname, bbox, landmark = self.imglist[idx]
              return label, self.read_image(fname), bbox, landmark
        else:
            s = self.imgrec.read()
            if s is None:
                raise StopIteration
            header, img = recordio.unpack(s)
            return header.label, img, None, None 
Example 5
Project: 1.FaceRecognition   Author: 944284742   File: data.py    License: MIT License 4 votes vote down vote up
def next_sample(self):
        """Helper function for reading in next sample."""
        #set total batch size, for example, 1800, and maximum size for each people, for example 45
        if self.seq is not None:
          while True:
            if self.cur >= len(self.seq):
                raise StopIteration
            idx = self.seq[self.cur]
            self.cur += 1
            if self.imgrec is not None:
              s = self.imgrec.read_idx(idx)
              header, img = recordio.unpack(s)
              label = header.label
              if self.output_c2c:
                count = self.idx2flag[idx]
                if self.output_c2c==1:
                  v = np.random.uniform(0.4, 0.5)
                elif self.output_c2c==2:
                  v = np.random.uniform(0.4, 0.5)
                  if count>=self.output_c2c:
                    v = np.random.uniform(0.3, 0.4)
                elif self.output_c2c==3:
                  v = (9.5 - math.log(2.0+count))/10.0
                  v = min(max(v, 0.3), 0.5)
                elif self.output_c2c==4:
                  mu = 0.0
                  sigma = 0.1
                  mrange = [0.4,0.5]
                  v = numpy.random.normal(mu, sigma)
                  v = math.abs(v)*-1.0+mrange[1]
                  v = max(v, mrange[0])
                elif self.output_c2c==5:
                  v = np.random.uniform(0.41, 0.51)
                  if count>=175:
                    v = np.random.uniform(0.37, 0.47)
                elif self.output_c2c==6:
                  v = np.random.uniform(0.41, 0.51)
                  if count>=175:
                    v = np.random.uniform(0.38, 0.48)
                else:
                  assert False

                label = [label, v]
              else:
                if not isinstance(label, numbers.Number):
                  label = label[0]
              return label, img, None, None
            else:
              label, fname, bbox, landmark = self.imglist[idx]
              return label, self.read_image(fname), bbox, landmark
        else:
            s = self.imgrec.read()
            if s is None:
                raise StopIteration
            header, img = recordio.unpack(s)
            return header.label, img, None, None 
Example 6
Project: MaskInsightface   Author: bleakie   File: data.py    License: Apache License 2.0 4 votes vote down vote up
def next_sample(self):
        """Helper function for reading in next sample."""
        #set total batch size, for example, 1800, and maximum size for each people, for example 45
        if self.seq is not None:
          while True:
            if self.cur >= len(self.seq):
                raise StopIteration
            idx = self.seq[self.cur]
            self.cur += 1
            if self.imgrec is not None:
              s = self.imgrec.read_idx(idx)
              header, img = recordio.unpack(s)
              label = header.label
              if self.output_c2c:
                count = self.idx2flag[idx]
                if self.output_c2c==1:
                  v = np.random.uniform(0.4, 0.5)
                elif self.output_c2c==2:
                  v = np.random.uniform(0.4, 0.5)
                  if count>=self.output_c2c:
                    v = np.random.uniform(0.3, 0.4)
                elif self.output_c2c==3:
                  v = (9.5 - math.log(2.0+count))/10.0
                  v = min(max(v, 0.3), 0.5)
                elif self.output_c2c==4:
                  mu = 0.0
                  sigma = 0.1
                  mrange = [0.4,0.5]
                  v = numpy.random.normal(mu, sigma)
                  v = math.abs(v)*-1.0+mrange[1]
                  v = max(v, mrange[0])
                elif self.output_c2c==5:
                  v = np.random.uniform(0.41, 0.51)
                  if count>=175:
                    v = np.random.uniform(0.37, 0.47)
                elif self.output_c2c==6:
                  v = np.random.uniform(0.41, 0.51)
                  if count>=175:
                    v = np.random.uniform(0.38, 0.48)
                else:
                  assert False

                label = [label, v]
              else:
                if not isinstance(label, numbers.Number):
                  label = label[0]
              return label, img, None, None
            else:
              label, fname, bbox, landmark = self.imglist[idx]
              return label, self.read_image(fname), bbox, landmark
        else:
            s = self.imgrec.read()
            if s is None:
                raise StopIteration
            header, img = recordio.unpack(s)
            return header.label, img, None, None