Move timeline pagerank code to core/algorithm (#1632)
This commit moves a lot of code and algorithms for computing timeline cred scores into `core/algorithm`. The `TimelineCred` module hasn't been moved, because it isn't clean enough for core -- it has dependencies on analysis and types, for example. This is another material step towards consolidating all of the SourceCred algorithm logic into `core/algorithm`, although there's still more to be done. Test plan: It's just a code reorg; `yarn test` is sufficient.
This commit is contained in:
parent
5b2f38114b
commit
c9958e346e
|
@ -5,9 +5,9 @@ import sortBy from "lodash.sortby";
|
||||||
import * as NullUtil from "../../util/null";
|
import * as NullUtil from "../../util/null";
|
||||||
import * as MapUtil from "../../util/map";
|
import * as MapUtil from "../../util/map";
|
||||||
import {toCompat, fromCompat, type Compatible} from "../../util/compat";
|
import {toCompat, fromCompat, type Compatible} from "../../util/compat";
|
||||||
import {type Interval} from "./interval";
|
import {type Interval} from "../../core/interval";
|
||||||
import {timelinePagerank} from "./timelinePagerank";
|
import {timelinePagerank} from "../../core/algorithm/timelinePagerank";
|
||||||
import {distributionToCred} from "./distributionToCred";
|
import {distributionToCred} from "../../core/algorithm/distributionToCred";
|
||||||
import {type PluginDeclaration} from "../pluginDeclaration";
|
import {type PluginDeclaration} from "../pluginDeclaration";
|
||||||
import {type NodeAddressT, NodeAddress, type Node} from "../../core/graph";
|
import {type NodeAddressT, NodeAddress, type Node} from "../../core/graph";
|
||||||
import * as WeightedGraph from "../../core/weightedGraph";
|
import * as WeightedGraph from "../../core/weightedGraph";
|
||||||
|
@ -25,7 +25,7 @@ import {
|
||||||
defaultParams,
|
defaultParams,
|
||||||
} from "./params";
|
} from "./params";
|
||||||
|
|
||||||
export type {Interval} from "./interval";
|
export type {Interval} from "../../core/interval";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A Graph Node wrapped with cred information.
|
* A Graph Node wrapped with cred information.
|
||||||
|
|
|
@ -3,7 +3,10 @@
|
||||||
import type {Edge} from "../core/graph";
|
import type {Edge} from "../core/graph";
|
||||||
import type {Weights} from "../core/weights";
|
import type {Weights} from "../core/weights";
|
||||||
import type {EdgeEvaluator} from "./pagerank";
|
import type {EdgeEvaluator} from "./pagerank";
|
||||||
import {nodeWeightEvaluator, edgeWeightEvaluator} from "./weightEvaluator";
|
import {
|
||||||
|
nodeWeightEvaluator,
|
||||||
|
edgeWeightEvaluator,
|
||||||
|
} from "../core/algorithm/weightEvaluator";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given the weight choices and the node and edge types, produces an edge
|
* Given the weight choices and the node and edge types, produces an edge
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {sum} from "d3-array";
|
import {sum} from "d3-array";
|
||||||
import {type Interval} from "./interval";
|
import {type Interval} from "../interval";
|
||||||
import {type TimelineDistributions} from "./timelinePagerank";
|
import {type TimelineDistributions} from "./timelinePagerank";
|
||||||
import {NodeAddress, type NodeAddressT} from "../../core/graph";
|
import {NodeAddress, type NodeAddressT} from "../../core/graph";
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import {NodeAddress} from "../../core/graph";
|
import {NodeAddress} from "../graph";
|
||||||
import {distributionToCred} from "./distributionToCred";
|
import {distributionToCred} from "./distributionToCred";
|
||||||
|
|
||||||
describe("src/analysis/timeline/distributionToCred", () => {
|
describe("src/core/algorithm/distributionToCred", () => {
|
||||||
const na = (...parts) => NodeAddress.fromParts(parts);
|
const na = (...parts) => NodeAddress.fromParts(parts);
|
||||||
describe("distributionToCred", () => {
|
describe("distributionToCred", () => {
|
||||||
it("works in a case where all nodes are scoring", () => {
|
it("works in a case where all nodes are scoring", () => {
|
|
@ -6,26 +6,26 @@
|
||||||
import deepFreeze from "deep-freeze";
|
import deepFreeze from "deep-freeze";
|
||||||
import {sum} from "d3-array";
|
import {sum} from "d3-array";
|
||||||
import * as NullUtil from "../../util/null";
|
import * as NullUtil from "../../util/null";
|
||||||
import {Graph, type NodeAddressT, type Edge, type Node} from "../../core/graph";
|
import {Graph, type NodeAddressT, type Edge, type Node} from "../graph";
|
||||||
import {type WeightedGraph} from "../../core/weightedGraph";
|
import {type WeightedGraph} from "../weightedGraph";
|
||||||
import {type Interval, partitionGraph} from "./interval";
|
import {type Interval, partitionGraph} from "../interval";
|
||||||
import {
|
import {
|
||||||
nodeWeightEvaluator,
|
nodeWeightEvaluator,
|
||||||
edgeWeightEvaluator,
|
edgeWeightEvaluator,
|
||||||
type NodeWeightEvaluator,
|
type NodeWeightEvaluator,
|
||||||
type EdgeWeightEvaluator,
|
type EdgeWeightEvaluator,
|
||||||
} from "../weightEvaluator";
|
} from "./weightEvaluator";
|
||||||
import {weightedDistribution} from "../../core/algorithm/nodeDistribution";
|
import {weightedDistribution} from "./nodeDistribution";
|
||||||
import {type Distribution} from "../../core/algorithm/distribution";
|
import {type Distribution} from "./distribution";
|
||||||
import {
|
import {
|
||||||
createOrderedSparseMarkovChain,
|
createOrderedSparseMarkovChain,
|
||||||
createConnections,
|
createConnections,
|
||||||
} from "../../core/algorithm/graphToMarkovChain";
|
} from "./graphToMarkovChain";
|
||||||
import {
|
import {
|
||||||
findStationaryDistribution,
|
findStationaryDistribution,
|
||||||
type PagerankParams,
|
type PagerankParams,
|
||||||
type SparseMarkovChain,
|
type SparseMarkovChain,
|
||||||
} from "../../core/algorithm/markovChain";
|
} from "./markovChain";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents raw PageRank distributions on a graph over time.
|
* Represents raw PageRank distributions on a graph over time.
|
|
@ -2,17 +2,17 @@
|
||||||
|
|
||||||
import {sum} from "d3-array";
|
import {sum} from "d3-array";
|
||||||
import * as NullUtil from "../../util/null";
|
import * as NullUtil from "../../util/null";
|
||||||
import {node, edge} from "../../core/graphTestUtil";
|
import {node, edge} from "../graphTestUtil";
|
||||||
import {Graph, type EdgeAddressT, type Edge} from "../../core/graph";
|
import {Graph, type EdgeAddressT, type Edge} from "../graph";
|
||||||
import {_timelineNodeWeights, _timelineMarkovChain} from "./timelinePagerank";
|
import {_timelineNodeWeights, _timelineMarkovChain} from "./timelinePagerank";
|
||||||
import {
|
import {
|
||||||
createConnections,
|
createConnections,
|
||||||
createOrderedSparseMarkovChain,
|
createOrderedSparseMarkovChain,
|
||||||
type EdgeWeight,
|
type EdgeWeight,
|
||||||
} from "../../core/algorithm/graphToMarkovChain";
|
} from "./graphToMarkovChain";
|
||||||
import {type SparseMarkovChain} from "../../core/algorithm/markovChain";
|
import {type SparseMarkovChain} from "./markovChain";
|
||||||
|
|
||||||
describe("src/analysis/timeline/timelinePagerank", () => {
|
describe("src/core/algorithm/timelinePagerank", () => {
|
||||||
describe("_timelineNodeWeights", () => {
|
describe("_timelineNodeWeights", () => {
|
||||||
it("works in a simple case", () => {
|
it("works in a simple case", () => {
|
||||||
const foo = node("foo");
|
const foo = node("foo");
|
|
@ -1,12 +1,8 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import type {NodeAddressT, EdgeAddressT} from "../core/graph";
|
import type {NodeAddressT, EdgeAddressT} from "../graph";
|
||||||
import type {
|
import type {Weights as WeightsT, EdgeWeight, NodeWeight} from "../weights";
|
||||||
Weights as WeightsT,
|
import {NodeTrie, EdgeTrie} from "../trie";
|
||||||
EdgeWeight,
|
|
||||||
NodeWeight,
|
|
||||||
} from "../core/weights";
|
|
||||||
import {NodeTrie, EdgeTrie} from "../core/trie";
|
|
||||||
|
|
||||||
export type NodeWeightEvaluator = (NodeAddressT) => NodeWeight;
|
export type NodeWeightEvaluator = (NodeAddressT) => NodeWeight;
|
||||||
export type EdgeWeightEvaluator = (EdgeAddressT) => EdgeWeight;
|
export type EdgeWeightEvaluator = (EdgeAddressT) => EdgeWeight;
|
|
@ -1,10 +1,10 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import {NodeAddress, EdgeAddress} from "../core/graph";
|
import {NodeAddress, EdgeAddress} from "../graph";
|
||||||
import {nodeWeightEvaluator, edgeWeightEvaluator} from "./weightEvaluator";
|
import {nodeWeightEvaluator, edgeWeightEvaluator} from "./weightEvaluator";
|
||||||
import * as Weights from "../core/weights";
|
import * as Weights from "../weights";
|
||||||
|
|
||||||
describe("src/analysis/weightEvaluator", () => {
|
describe("src/core/algorithm/weightEvaluator", () => {
|
||||||
describe("nodeWeightEvaluator", () => {
|
describe("nodeWeightEvaluator", () => {
|
||||||
const empty = NodeAddress.fromParts([]);
|
const empty = NodeAddress.fromParts([]);
|
||||||
const foo = NodeAddress.fromParts(["foo"]);
|
const foo = NodeAddress.fromParts(["foo"]);
|
|
@ -3,8 +3,8 @@
|
||||||
import {max, min} from "d3-array";
|
import {max, min} from "d3-array";
|
||||||
import sortBy from "lodash.sortby";
|
import sortBy from "lodash.sortby";
|
||||||
import {utcWeek} from "d3-time";
|
import {utcWeek} from "d3-time";
|
||||||
import * as NullUtil from "../../util/null";
|
import * as NullUtil from "../util/null";
|
||||||
import type {Node, Edge, Graph} from "../../core/graph";
|
import type {Node, Edge, Graph} from "./graph";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents a time interval
|
* Represents a time interval
|
|
@ -1,11 +1,11 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import {utcWeek} from "d3-time";
|
import {utcWeek} from "d3-time";
|
||||||
import {node, edge} from "../../core/graphTestUtil";
|
import {node, edge} from "./graphTestUtil";
|
||||||
import {Graph} from "../../core/graph";
|
import {Graph} from "./graph";
|
||||||
import {partitionGraph, graphIntervals, weekIntervals} from "./interval";
|
import {partitionGraph, graphIntervals, weekIntervals} from "./interval";
|
||||||
|
|
||||||
describe("src/analysis/timeline/interval", () => {
|
describe("src/core/interval", () => {
|
||||||
const WEEK_MID = 1562501362239;
|
const WEEK_MID = 1562501362239;
|
||||||
const WEEK_START = +utcWeek.floor(WEEK_MID);
|
const WEEK_START = +utcWeek.floor(WEEK_MID);
|
||||||
const WEEK_END = +utcWeek.ceil(WEEK_MID);
|
const WEEK_END = +utcWeek.ceil(WEEK_MID);
|
Loading…
Reference in New Issue