平均绝对偏差 mean absolute deviation
    修正: 2018-05-25 

    之前用mad的计算模式依然返回的是单值
495713
def AVEDEV(Series, N):
    
    return Series.rolling(N).apply(lambda x: (np.abs(x - x.mean())).mean(), raw=True)
167624
def tdb_minus_tt(jd_tdb):
    
    t = (jd_tdb - T0) / 36525.0

    # USNO Circular 179, eq. 2.6.
    return (0.001657 * sin ( 628.3076 * t + 6.2401)
          + 0.000022 * sin ( 575.3385 * t + 4.2970)
          + 0.000014 * sin (1256.6152 * t + 6.1969)
          + 0.000005 * sin ( 606.9777 * t + 4.0212)
          + 0.000005 * sin (  52.9691 * t + 0.4444)
          + 0.000002 * sin (  21.3299 * t + 5.5431)
          + 0.000010 * t * sin ( 628.3076 * t + 4.2490))
1314165
function glyfAdjust(g, scaleX, scaleY, offsetX, offsetY, useCeil) {

    scaleX = scaleX || 1;
    scaleY = scaleY || 1;
    offsetX = offsetX || 0;
    offsetY = offsetY || 0;

    if (g.contours && g.contours.length) {
        if (scaleX !== 1 || scaleY !== 1) {
            g.contours.forEach(function (contour) {
                pathAdjust(contour, scaleX, scaleY);
            });
        }

        if (offsetX !== 0 || offsetY !== 0) {
            g.contours.forEach(function (contour) {
                pathAdjust(contour, 1, 1, offsetX, offsetY);
            });
        }

        if (false !== useCeil) {
            g.contours.forEach(function (contour) {
                pathCeil(contour);
            });
        }
    }

    // 重新计算xmin，xmax，ymin，ymax
    var advanceWidth = g.advanceWidth;
    if (
        undefined === g.xMin
        || undefined === g.yMax
        || undefined === g.leftSideBearing
        || undefined === g.advanceWidth
    ) {
        // 有的字形没有形状，需要特殊处理一下
        var bound;
        if (g.contours && g.contours.length) {
            bound = computeBoundingBox.computePathBox.apply(this, g.contours);
        }
        else {
            bound = {
                x: 0,
                y: 0,
                width: 0,
                height: 0
            };
        }

        g.xMin = bound.x;
        g.xMax = bound.x + bound.width;
        g.yMin = bound.y;
        g.yMax = bound.y + bound.height;

        g.leftSideBearing = g.xMin;

        // 如果设置了advanceWidth就是用默认的，否则为xMax + abs(xMin)
        if (undefined !== advanceWidth) {
            g.advanceWidth = Math.round(advanceWidth * scaleX + offsetX);
        }
        else {
            g.advanceWidth = g.xMax + Math.abs(g.xMin);
        }
    }
    else {
        g.xMin = Math.round(g.xMin * scaleX + offsetX);
        g.xMax = Math.round(g.xMax * scaleX + offsetX);
        g.yMin = Math.round(g.yMin * scaleY + offsetY);
        g.yMax = Math.round(g.yMax * scaleY + offsetY);
        g.leftSideBearing = Math.round(g.leftSideBearing * scaleX + offsetX);
        g.advanceWidth = Math.round(advanceWidth * scaleX + offsetX);
    }

    return g;
}
93906
def get_mean_and_stddevs(self, sites, rup, dists, imt, stddev_types):
        
        # Check that the requested standard deviation type is available
        assert all(stddev_type in self.DEFINED_FOR_STANDARD_DEVIATION_TYPES
                   for stddev_type in stddev_types)
        #
        # Set parameters
        magn = rup.mag
        epi = dists.repi
        theta = dists.azimuth
        #
        # Convert Mw into Ms
        if magn < 6.58:
            mag = (magn - 0.59) / 0.86
        else:
            mag = (magn + 2.42) / 1.28
        #
        # Set coefficients
        coeff = self.COEFFS[imt]
        a1ca, a1cb, a1cc, a1cd, a1ce, a2ca, a2cb, a2cc, a2cd, a2ce = \
            gc(coeff, mag)
        #
        # Get correction coefficients. Here for each site we find the
        # the geometry of the ellipses
        ras = []
        for epi, theta in zip(dists.repi, dists.azimuth):
            res = get_ras(epi, theta, mag, coeff)
            ras.append(res)
        ras = np.array(ras)
        rbs = rbf(ras, coeff, mag)
        #
        # Compute values of ground motion for the two cases. The value of
        # 225 is hardcoded under the assumption that the hypocentral depth
        # corresponds to 15 km (i.e. 15**2)
        mean1 = (a1ca + a1cb * mag +
                 a1cc * np.log((ras**2+225)**0.5 +
                               a1cd * np.exp(a1ce * mag)))
        mean2 = (a2ca + a2cb * mag +
                 a2cc * np.log((rbs**2+225)**0.5 +
                               a2cd * np.exp(a2ce * mag)))
        #
        # Get distances
        x = (mean1 * np.sin(np.radians(dists.azimuth)))**2
        y = (mean2 * np.cos(np.radians(dists.azimuth)))**2
        mean = mean1 * mean2 / np.sqrt(x+y)
        if imt.name == "PGA":
            mean = np.exp(mean)/g/100
        elif imt.name == "PGV":
            mean = np.exp(mean)
        else:
            raise ValueError('Unsupported IMT')
        #
        # Get the standard deviation
        stddevs = self._compute_std(coeff, stddev_types, len(dists.repi))
        #
        # Return results
        return np.log(mean), stddevs
553346
public void norm_setTotal() {
        String rule;
        Pattern pattern;
        Matcher match;
        String[] tmp_parser;
        String tmp_target;

        /*
         * 修改了函数中所有的匹配规则使之更为严格
         * modified by 曹零
         */
        rule = "(?<!(周|星期))([0-2]?[0-9]):[0-5]?[0-9]:[0-5]?[0-9]";
        pattern = Pattern.compile(rule);
        match = pattern.matcher(Time_Expression);
        if (match.find()) {
            tmp_parser = new String[3];
            tmp_target = match.group();
            tmp_parser = tmp_target.split(":");
            _tp.tunit[3] = Integer.parseInt(tmp_parser[0]);
            _tp.tunit[4] = Integer.parseInt(tmp_parser[1]);
            _tp.tunit[5] = Integer.parseInt(tmp_parser[2]);
        } /*
         * 添加了省略秒的:固定形式的时间规则匹配
         * add by 曹零
         */ else {
            rule = "(?<!(周|星期))([0-2]?[0-9]):[0-5]?[0-9]";
            pattern = Pattern.compile(rule);
            match = pattern.matcher(Time_Expression);
            if (match.find()) {
                tmp_parser = new String[2];
                tmp_target = match.group();
                tmp_parser = tmp_target.split(":");
                _tp.tunit[3] = Integer.parseInt(tmp_parser[0]);
                _tp.tunit[4] = Integer.parseInt(tmp_parser[1]);
            }
        }
        /*
         * 增加了:固定形式时间表达式的
         * 中午,午间,下午,午后,晚上,傍晚,晚间,晚,pm,PM
         * 的正确时间计算，规约同上
         * add by 曹零
         */
        rule = "(中午)|(午间)";
        pattern = Pattern.compile(rule);
        match = pattern.matcher(Time_Expression);
        if (match.find()) {
            if (_tp.tunit[3] >= 0 && _tp.tunit[3] <= 10) {
                _tp.tunit[3] += 12;
            }
        }

        rule = "(下午)|(午后)|(pm)|(PM)";
        pattern = Pattern.compile(rule);
        match = pattern.matcher(Time_Expression);
        if (match.find()) {
            if (_tp.tunit[3] >= 0 && _tp.tunit[3] <= 11) {
                _tp.tunit[3] += 12;
            }
        }

        rule = "晚";
        pattern = Pattern.compile(rule);
        match = pattern.matcher(Time_Expression);
        if (match.find()) {
            if (_tp.tunit[3] >= 1 && _tp.tunit[3] <= 11) {
                _tp.tunit[3] += 12;
            } else if (_tp.tunit[3] == 12) {
                _tp.tunit[3] = 0;
            }
        }


        rule = "[0-9]?[0-9]?[0-9]{2}-((10)|(11)|(12)|([1-9]))-((?<!\\d))([0-3][0-9]|[1-9])";
        pattern = Pattern.compile(rule);
        match = pattern.matcher(Time_Expression);
        if (match.find()) {
            tmp_parser = new String[3];
            tmp_target = match.group();
            tmp_parser = tmp_target.split("-");
            _tp.tunit[0] = Integer.parseInt(tmp_parser[0]);
            _tp.tunit[1] = Integer.parseInt(tmp_parser[1]);
            _tp.tunit[2] = Integer.parseInt(tmp_parser[2]);
        }

        rule = "((10)|(11)|(12)|([1-9]))/((?<!\\d))([0-3][0-9]|[1-9])/[0-9]?[0-9]?[0-9]{2}";
        pattern = Pattern.compile(rule);
        match = pattern.matcher(Time_Expression);
        if (match.find()) {
            tmp_parser = new String[3];
            tmp_target = match.group();
            tmp_parser = tmp_target.split("/");
            _tp.tunit[1] = Integer.parseInt(tmp_parser[0]);
            _tp.tunit[2] = Integer.parseInt(tmp_parser[1]);
            _tp.tunit[0] = Integer.parseInt(tmp_parser[2]);
        }

        /*
         * 增加了:固定形式时间表达式 年.月.日 的正确识别
         * add by 曹零
         */
        rule = "[0-9]?[0-9]?[0-9]{2}\\.((10)|(11)|(12)|([1-9]))\\.((?<!\\d))([0-3][0-9]|[1-9])";
        pattern = Pattern.compile(rule);
        match = pattern.matcher(Time_Expression);
        if (match.find()) {
            tmp_parser = new String[3];
            tmp_target = match.group();
            tmp_parser = tmp_target.split("\\.");
            _tp.tunit[0] = Integer.parseInt(tmp_parser[0]);
            _tp.tunit[1] = Integer.parseInt(tmp_parser[1]);
            _tp.tunit[2] = Integer.parseInt(tmp_parser[2]);
        }
    }
42383
function adjustPos(glyfList, leftSideBearing, rightSideBearing, verticalAlign) {

            var changed = false;

            // 左边轴
            if (null != leftSideBearing) {
                changed = true;

                glyfList.forEach(function (g) {
                    if (g.leftSideBearing !== leftSideBearing) {
                        glyfAdjust(g, 1, 1, leftSideBearing - g.leftSideBearing);
                    }
                });
            }

            // 右边轴
            if (null != rightSideBearing) {
                changed = true;

                glyfList.forEach(function (g) {
                    g.advanceWidth = g.xMax + rightSideBearing;
                });
            }

            // 基线高度
            if (null != verticalAlign) {
                changed = true;

                glyfList.forEach(function (g) {
                    if (g.contours && g.contours.length) {
                        var bound = computeBoundingBox.computePath.apply(this, g.contours);
                        var offset = verticalAlign - bound.y;
                        glyfAdjust(g, 1, 1, 0, offset);
                    }
                });
            }

            return changed ? glyfList : [];
        }
1115356
function computeStripY() {
      if (this.hideVertical) {
        // 没有开启竖向滚动条
        return;
      }
      var clientEle = this.$refs['happy-scroll'];
      var slotEle = this.$slots.default[0]['elm'];
      // 竖向滚动条高度与元素高度百分比
      this.$refs.stripY.computeStrip(slotEle.scrollHeight, clientEle.clientHeight);
    }
242964
function adjustmentPosition(position, operator, radicand, exponent) {
                var exponentBox = null, opOffset = {
                    x: 0,
                    y: 0
                }, opBox = operator.getFixRenderBox();
                exponent.scale(.66);
                exponentBox = exponent.getFixRenderBox();
                if (exponentBox.width > 0 && exponentBox.height > 0) {
                    opOffset.y = exponentBox.height - opBox.height / 2;
                    // 指数不超出根号， 则移动指数
                    if (opOffset.y < 0) {
                        exponent.translate(0, -opOffset.y);
                        opOffset.y = 0;
                    }
                    opOffset.x = exponentBox.width + opBox.height / 2 * tan15 - position.x;
                }
                operator.translate(opOffset.x, opOffset.y);
                radicand.translate(opOffset.x + position.x + SHAPE_DATA_WIDTH, opOffset.y + 2 * SHAPE_DATA_WIDTH);
            }
157576
function checkError( id, hard ) {
            if ( visited[ id ] || modIs( id, MODULE_DEFINED ) ) {
                return;
            }

            visited[ id ] = 1;

            if ( !modIs( id, MODULE_PREPARED ) ) {
                // HACK: 为gzip后体积优化，不做抽取
                if ( !hangModulesMap[ id ] ) {
                    hangModulesMap[ id ] = 1;
                    hangModules.push( id );
                }
            }

            var module = modModules[ id ];
            if ( !module ) {
                if ( !missModulesMap[ id ] ) {
                    missModulesMap[ id ] = 1;
                    missModules.push( id );
                }
            }
            else if ( hard ) {
                if ( !hangModulesMap[ id ] ) {
                    hangModulesMap[ id ] = 1;
                    hangModules.push( id );
                }

                each(
                    module.depMs,
                    function ( dep ) {
                        checkError( dep.absId, dep.hard );
                    }
                );
            }
        }
1153751
def errors(self):
        

        n = self.n
        dt = self.dt
        order = self._order
        sigma = self.sigma

        error = np.zeros(order + 1)
        std = np.zeros(order + 1)

        if n == 0:
            return (error, std)

        if order == 0:
            error[0] = sigma/sqrt(n)
            std[0] = sigma/sqrt(n)

        elif order == 1:
            if n > 1:
                error[0] = sigma * sqrt(2*(2*n-1) / (n*(n+1)))
                error[1] = sigma * sqrt(12. / (n*(n*n-1)*dt*dt))
            std[0] = sigma * sqrt((2*(2*n-1)) / (n*(n+1)))
            std[1] = (sigma/dt) * sqrt(12. / (n*(n*n-1)))

        elif order == 2:
            dt2 = dt * dt

            if n >= 3:
                error[0] = sigma * sqrt(3*(3*n*n-3*n+2) / (n*(n+1)*(n+2)))
                error[1] = sigma * sqrt(12*(16*n*n-30*n+11) /
                                        (n*(n*n-1)*(n*n-4)*dt2))
                error[2] = sigma * sqrt(720/(n*(n*n-1)*(n*n-4)*dt2*dt2))

            std[0] = sigma * sqrt((3*(3*n*n - 3*n + 2)) / (n*(n+1)*(n+2)))
            std[1] = (sigma/dt) * sqrt((12*(16*n*n - 30*n + 11)) /
                                       (n*(n*n - 1)*(n*n - 4)))
            std[2] = (sigma/dt2) * sqrt(720 / (n*(n*n-1)*(n*n-4)))

        return error, std
150820
def _get_deviation_of_mean(self, series, multiplier=3):
        
        capped_series = np.minimum(
            series, series.mean() + multiplier * series.std())
        count = pd.value_counts(series != capped_series)
        count = count[True] if True in count else 0
        perc = self._percent(count / self.length)
        return count, perc
1028097
function fixLinearGradient (args) {
	const angle = parseAngle(args[0][0]);

	if (angle) {
		// 如果第一参数是角度，修正角度
		const deg = Math.round(angle.deg);
		if (deg === 180) {
			// 180°正是浏览器默认值，所以抛弃，减少生成的css的体积
			args.shift();
		} else {
			if (degMap[deg]) {
				// 如果角度是0、90、180、270等特殊值，将第一参变为方位信息
				args[0] = ["to", degMap[deg]];
			} else {
				// 其他角度值，直接转换第一参即可
				args[0] = angle2String(angle);
			}
		}
	} else {
		let position;
		// 遍历第一参中的值，
		args[0].forEach((arg, i) => {
			if (directionMap[arg]) {
				// 将top、left、bottom、right取反义词，并记录position
				args[0][i] = directionMap[arg];
				position = args[0];
			}
		});
		if (position) {
			if (position.length === 1 && position[0] === "bottom") {
				// `to bottom`正是浏览器默认值，所以抛弃，减少生成的css的体积
				args.shift();
			} else {
				// 将方位信息最前面添加一个"to"二级参数
				position.unshift("to");
			}
		}
	}

	return args;
}
150342
def mad(v):
    
    return np.median(np.abs(v - np.median(v)))
1045506
def _compute_mean(self, C, mag, dists, rake):
        
        mean = (
            self._compute_magnitude_scaling_term(C, mag) +
            self._compute_geometric_decay_term(C, mag, dists) +
            self._compute_faulting_style_term(C, rake) +
            self._compute_anelestic_attenuation_term(C, dists)
        )

        return mean
299740
def get_mean_DRAT(sum_ptrm_checks, sum_abs_ptrm_checks, n_pTRM, L):
    
    if not n_pTRM:
        return float('nan'), float('nan')
    mean_DRAT = ((old_div(1., n_pTRM)) * (old_div(sum_ptrm_checks, L))) * 100
    mean_DRAT_prime = ((old_div(1., n_pTRM)) * (old_div(sum_abs_ptrm_checks, L))) * 100
    return mean_DRAT, mean_DRAT_prime
1183718
def get_stddevs(self, mean, stddev_types):
        
        mean = np.exp(mean)
        sigma = 0.39 + np.zeros(mean.shape)
        sigma[mean < 0.068] = 0.55
        idx = np.logical_and(mean >= 0.068, mean <= 0.21)
        sigma[idx] = 0.173- 0.140 * np.log(mean[idx])
        stddevs = []
        for stddev in stddev_types:
            if stddev == const.StdDev.TOTAL:
                stddevs.append(sigma)
        return stddevs
1270528
function fixRadialGradient (args) {
	let firstArg = [];
	let position;

	// 分析所有参数，将坐标参数和关键字剔除出args并单独保存
	args = args.filter((subArg) => {
		let hasKeyWord;
		subArg.forEach((word, i) => {
			if (keyWordMap[word]) {
				// 查找需要转换的关键字
				subArg[i] = keyWordMap[word];
				hasKeyWord = true;
			} else if (/^(?:circle|ellipse|\w+-\w+)$/.test(word)) {
				// 查找是否有其他的关键字
				hasKeyWord = true;
			}
		});
		if (hasKeyWord) {
			// subArg中如果有关键字，将它存入firstArg
			firstArg = firstArg.concat(subArg);
			return false;
		} else if (subArg.every((word) => {
			return word === "center" || directionMap[word] || parseNum(word);
		})) {
			// 如果subArg是坐标信息将它存入position
			position = subArg;
			return false;
		}
		return true;
	});

	if (position) {
		// 在坐标参数最前面添加`at`关键字
		position.unshift("at");
		firstArg = firstArg.concat(position);
	}

	if (firstArg.length) {
		// 如果收集到了firstArg，将其加入args的最前面
		args.unshift(firstArg);
	}

	return args;
}