import numpy as np


def effectiveSampleSize(data, stepSize = 1) :
  """ Effective sample size, as computed by BEAST Tracer."""
  samples = len(data)

  assert len(data) > 1,"no stats for short sequences"
  
  maxLag = min(samples//3, 1000)

  gammaStat = [0,]*maxLag
  #varGammaStat = [0,]*maxLag

  varStat = 0.0

  if type(data) != np.ndarray :
    data = np.array(data)

  normalizedData = data - data.mean()
  
  for lag in range(maxLag) :
    v1 = normalizedData[:samples-lag]
    v2 = normalizedData[lag:]
    v = v1 * v2
    gammaStat[lag] = sum(v) / len(v)
    #varGammaStat[lag] = sum(v*v) / len(v)
    #varGammaStat[lag] -= gammaStat[0] ** 2

    # print lag, gammaStat[lag], varGammaStat[lag]
    
    if lag == 0 :
      varStat = gammaStat[0]
    elif lag % 2 == 0 :
      s = gammaStat[lag-1] + gammaStat[lag]
      if s > 0 :
         varStat += 2.0*s
      else :
        break
      
  # standard error of mean
  # stdErrorOfMean = Math.sqrt(varStat/samples);

  # auto correlation time
  act = stepSize * varStat / gammaStat[0]

  # effective sample size
  ess = (stepSize * samples) / act

  return ess
e8ae1bcf2c917d94e6b88db6a474530e13f66597
<mask token>

<mask token>


def effectiveSampleSize(data, stepSize=1):
    """ Effective sample size, as computed by BEAST Tracer."""
    samples = len(data)
    assert len(data) > 1, 'no stats for short sequences'
    maxLag = min(samples // 3, 1000)
    gammaStat = [0] * maxLag
    varStat = 0.0
    if type(data) != np.ndarray:
        data = np.array(data)
    normalizedData = data - data.mean()
    for lag in range(maxLag):
        v1 = normalizedData[:samples - lag]
        v2 = normalizedData[lag:]
        v = v1 * v2
        gammaStat[lag] = sum(v) / len(v)
        if lag == 0:
            varStat = gammaStat[0]
        elif lag % 2 == 0:
            s = gammaStat[lag - 1] + gammaStat[lag]
            if s > 0:
                varStat += 2.0 * s
            else:
                break
    act = stepSize * varStat / gammaStat[0]
    ess = stepSize * samples / act
    return ess

import numpy as np


def effectiveSampleSize(data, stepSize=1):
    """ Effective sample size, as computed by BEAST Tracer."""
    samples = len(data)
    assert len(data) > 1, 'no stats for short sequences'
    maxLag = min(samples // 3, 1000)
    gammaStat = [0] * maxLag
    varStat = 0.0
    if type(data) != np.ndarray:
        data = np.array(data)
    normalizedData = data - data.mean()
    for lag in range(maxLag):
        v1 = normalizedData[:samples - lag]
        v2 = normalizedData[lag:]
        v = v1 * v2
        gammaStat[lag] = sum(v) / len(v)
        if lag == 0:
            varStat = gammaStat[0]
        elif lag % 2 == 0:
            s = gammaStat[lag - 1] + gammaStat[lag]
            if s > 0:
                varStat += 2.0 * s
            else:
                break
    act = stepSize * varStat / gammaStat[0]
    ess = stepSize * samples / act
    return ess

import numpy as np


def effectiveSampleSize(data, stepSize = 1) :
  """ Effective sample size, as computed by BEAST Tracer."""
  samples = len(data)

  assert len(data) > 1,"no stats for short sequences"
  
  maxLag = min(samples//3, 1000)

  gammaStat = [0,]*maxLag
  #varGammaStat = [0,]*maxLag

  varStat = 0.0

  if type(data) != np.ndarray :
    data = np.array(data)

  normalizedData = data - data.mean()
  
  for lag in range(maxLag) :
    v1 = normalizedData[:samples-lag]
    v2 = normalizedData[lag:]
    v = v1 * v2
    gammaStat[lag] = sum(v) / len(v)
    #varGammaStat[lag] = sum(v*v) / len(v)
    #varGammaStat[lag] -= gammaStat[0] ** 2

    # print lag, gammaStat[lag], varGammaStat[lag]
    
    if lag == 0 :
      varStat = gammaStat[0]
    elif lag % 2 == 0 :
      s = gammaStat[lag-1] + gammaStat[lag]
      if s > 0 :
         varStat += 2.0*s
      else :
        break
      
  # standard error of mean
  # stdErrorOfMean = Math.sqrt(varStat/samples);

  # auto correlation time
  act = stepSize * varStat / gammaStat[0]

  # effective sample size
  ess = (stepSize * samples) / act

  return ess