mirror of
https://github.com/status-im/sourcecred.git
synced 2025-02-05 01:04:53 +00:00
parent
1689c46f20
commit
fed58aee7b
@ -7,7 +7,7 @@ import LocalStore from "./LocalStore";
|
||||
import {createPluginAdapter as createGithubAdapter} from "../../plugins/github/pluginAdapter";
|
||||
import {createPluginAdapter as createGitAdapter} from "../../plugins/git/pluginAdapter";
|
||||
import {Graph} from "../../core/graph";
|
||||
import {pagerank, type PagerankResult} from "../../core/attribution/pagerank";
|
||||
import {pagerank, type NodeDistribution} from "../../core/attribution/pagerank";
|
||||
import {PagerankTable} from "./PagerankTable";
|
||||
import type {PluginAdapter} from "../pluginAdapter";
|
||||
import {type EdgeEvaluator} from "../../core/attribution/pagerank";
|
||||
@ -24,7 +24,7 @@ type State = {
|
||||
+nodeCount: number,
|
||||
+edgeCount: number,
|
||||
|},
|
||||
+pagerankResult: ?PagerankResult,
|
||||
+pagerankResult: ?NodeDistribution,
|
||||
|},
|
||||
edgeEvaluator: ?EdgeEvaluator,
|
||||
};
|
||||
|
@ -13,13 +13,13 @@ import {
|
||||
EdgeAddress,
|
||||
type EdgeAddressT,
|
||||
} from "../../core/graph";
|
||||
import type {PagerankResult} from "../../core/attribution/pagerank";
|
||||
import type {NodeDistribution} from "../../core/attribution/pagerank";
|
||||
import type {PluginAdapter} from "../pluginAdapter";
|
||||
|
||||
const MAX_TABLE_ENTRIES = 100;
|
||||
|
||||
type Props = {
|
||||
pagerankResult: ?PagerankResult,
|
||||
pagerankResult: ?NodeDistribution,
|
||||
graph: ?Graph,
|
||||
adapters: ?$ReadOnlyArray<PluginAdapter>,
|
||||
};
|
||||
@ -198,7 +198,7 @@ type RTProps = {|
|
||||
// Present if this RT shows a neighbor (not a top-level node)
|
||||
+edge: ?Edge,
|
||||
+graph: Graph,
|
||||
+pagerankResult: PagerankResult,
|
||||
+pagerankResult: NodeDistribution,
|
||||
+depth: number,
|
||||
+adapters: $ReadOnlyArray<PluginAdapter>,
|
||||
|};
|
||||
@ -281,7 +281,7 @@ class RecursiveTable extends React.PureComponent<RTProps, RTState> {
|
||||
type NodesTablesProps = {|
|
||||
+addresses: $ReadOnlyArray<NodeAddressT>,
|
||||
+graph: Graph,
|
||||
+pagerankResult: PagerankResult,
|
||||
+pagerankResult: NodeDistribution,
|
||||
+depth: number,
|
||||
+adapters: $ReadOnlyArray<PluginAdapter>,
|
||||
|};
|
||||
@ -318,7 +318,7 @@ class NodesTables extends React.PureComponent<NodesTablesProps> {
|
||||
type NeighborsTablesProps = {|
|
||||
+neighbors: $ReadOnlyArray<Neighbor>,
|
||||
+graph: Graph,
|
||||
+pagerankResult: PagerankResult,
|
||||
+pagerankResult: NodeDistribution,
|
||||
+depth: number,
|
||||
+adapters: $ReadOnlyArray<PluginAdapter>,
|
||||
|};
|
||||
|
@ -33,7 +33,7 @@ export function contributorSource(
|
||||
}
|
||||
}
|
||||
|
||||
export type PagerankResult = Map<NodeAddressT, Probability>;
|
||||
export type NodeDistribution = Map<NodeAddressT, Probability>;
|
||||
|
||||
export type NodeToContributions = Map<
|
||||
NodeAddressT,
|
||||
@ -251,10 +251,10 @@ export function normalize(
|
||||
return normalizeNeighbors(permute(old, old.nodeOrder.slice().sort()));
|
||||
}
|
||||
|
||||
export function distributionToPagerankResult(
|
||||
export function distributionToNodeDistribution(
|
||||
nodeOrder: $ReadOnlyArray<NodeAddressT>,
|
||||
pi: Distribution
|
||||
): PagerankResult {
|
||||
): NodeDistribution {
|
||||
const result = new Map();
|
||||
nodeOrder.forEach((node, i) => {
|
||||
const probability = pi[i];
|
||||
|
@ -4,7 +4,7 @@ import sortBy from "lodash.sortby";
|
||||
|
||||
import {EdgeAddress, Graph, NodeAddress} from "../graph";
|
||||
import {
|
||||
distributionToPagerankResult,
|
||||
distributionToNodeDistribution,
|
||||
createContributions,
|
||||
createOrderedSparseMarkovChain,
|
||||
normalize,
|
||||
@ -278,12 +278,12 @@ describe("core/attribution/graphToMarkovChain", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("distributionToPagerankResult", () => {
|
||||
describe("distributionToNodeDistribution", () => {
|
||||
it("works", () => {
|
||||
const pi = new Float64Array([0.25, 0.75]);
|
||||
const n1 = NodeAddress.fromParts(["foo"]);
|
||||
const n2 = NodeAddress.fromParts(["bar"]);
|
||||
expect(distributionToPagerankResult([n1, n2], pi)).toEqual(
|
||||
expect(distributionToNodeDistribution([n1, n2], pi)).toEqual(
|
||||
new Map().set(n1, 0.25).set(n2, 0.75)
|
||||
);
|
||||
});
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
import {type Edge, Graph} from "../graph";
|
||||
import {
|
||||
type PagerankResult,
|
||||
distributionToPagerankResult,
|
||||
type NodeDistribution,
|
||||
distributionToNodeDistribution,
|
||||
createContributions,
|
||||
createOrderedSparseMarkovChain,
|
||||
type EdgeWeight,
|
||||
@ -11,7 +11,7 @@ import {
|
||||
|
||||
import {findStationaryDistribution} from "./markovChain";
|
||||
|
||||
export type {PagerankResult} from "./graphToMarkovChain";
|
||||
export type {NodeDistribution} from "./graphToMarkovChain";
|
||||
export type PagerankOptions = {|
|
||||
+selfLoopWeight?: number,
|
||||
+verbose?: boolean,
|
||||
@ -35,7 +35,7 @@ export function pagerank(
|
||||
graph: Graph,
|
||||
edgeWeight: EdgeEvaluator,
|
||||
options?: PagerankOptions
|
||||
): PagerankResult {
|
||||
): NodeDistribution {
|
||||
const fullOptions = {
|
||||
...defaultOptions(),
|
||||
...(options || {}),
|
||||
@ -51,5 +51,5 @@ export function pagerank(
|
||||
convergenceThreshold: fullOptions.convergenceThreshold,
|
||||
maxIterations: fullOptions.maxIterations,
|
||||
});
|
||||
return distributionToPagerankResult(osmc.nodeOrder, distribution);
|
||||
return distributionToNodeDistribution(osmc.nodeOrder, distribution);
|
||||
}
|
||||
|
@ -8,7 +8,7 @@ import {
|
||||
type NodeToContributions,
|
||||
contributorSource,
|
||||
} from "./graphToMarkovChain";
|
||||
import type {PagerankResult} from "./pagerank";
|
||||
import type {NodeDistribution} from "./pagerank";
|
||||
import * as MapUtil from "../../util/map";
|
||||
|
||||
export type ScoredContribution = {|
|
||||
@ -29,7 +29,7 @@ export type PagerankNodeDecomposition = Map<
|
||||
>;
|
||||
|
||||
export function decompose(
|
||||
pr: PagerankResult,
|
||||
pr: NodeDistribution,
|
||||
contributions: NodeToContributions
|
||||
): PagerankNodeDecomposition {
|
||||
return MapUtil.mapValues(contributions, (target, contributions) => {
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
import {EdgeAddress, Graph, NodeAddress, edgeToStrings} from "../graph";
|
||||
import {
|
||||
distributionToPagerankResult,
|
||||
distributionToNodeDistribution,
|
||||
createContributions,
|
||||
createOrderedSparseMarkovChain,
|
||||
} from "./graphToMarkovChain";
|
||||
@ -134,7 +134,7 @@ describe("core/attribution/contributions", () => {
|
||||
convergenceThreshold: 1e-6,
|
||||
maxIterations: 255,
|
||||
});
|
||||
const pr = distributionToPagerankResult(osmc.nodeOrder, pi);
|
||||
const pr = distributionToNodeDistribution(osmc.nodeOrder, pi);
|
||||
const result = decompose(pr, contributions);
|
||||
expect(formatDecomposition(result)).toMatchSnapshot();
|
||||
validateDecomposition(result);
|
||||
@ -150,7 +150,7 @@ describe("core/attribution/contributions", () => {
|
||||
convergenceThreshold: 1e-6,
|
||||
maxIterations: 255,
|
||||
});
|
||||
const pr = distributionToPagerankResult(osmc.nodeOrder, pi);
|
||||
const pr = distributionToNodeDistribution(osmc.nodeOrder, pi);
|
||||
const result = decompose(pr, contributions);
|
||||
validateDecomposition(result);
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user