@stevenvo780/st-lang 4.7.0 → 4.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/namespaces/reasoning.d.ts +2 -1
- package/dist/namespaces/reasoning.d.ts.map +1 -1
- package/dist/namespaces/reasoning.js +3 -1
- package/dist/namespaces/reasoning.js.map +1 -1
- package/dist/reasoning/combinatorial-games/index.d.ts +105 -0
- package/dist/reasoning/combinatorial-games/index.d.ts.map +1 -0
- package/dist/reasoning/combinatorial-games/index.js +377 -0
- package/dist/reasoning/combinatorial-games/index.js.map +1 -0
- package/dist/reasoning/mechanism-design/auctions.d.ts +49 -0
- package/dist/reasoning/mechanism-design/auctions.d.ts.map +1 -0
- package/dist/reasoning/mechanism-design/auctions.js +179 -0
- package/dist/reasoning/mechanism-design/auctions.js.map +1 -0
- package/dist/reasoning/mechanism-design/index.d.ts +5 -0
- package/dist/reasoning/mechanism-design/index.d.ts.map +1 -0
- package/dist/reasoning/mechanism-design/index.js +39 -0
- package/dist/reasoning/mechanism-design/index.js.map +1 -0
- package/dist/reasoning/mechanism-design/myerson.d.ts +64 -0
- package/dist/reasoning/mechanism-design/myerson.d.ts.map +1 -0
- package/dist/reasoning/mechanism-design/myerson.js +253 -0
- package/dist/reasoning/mechanism-design/myerson.js.map +1 -0
- package/dist/reasoning/mechanism-design/types.d.ts +44 -0
- package/dist/reasoning/mechanism-design/types.d.ts.map +1 -0
- package/dist/reasoning/mechanism-design/types.js +22 -0
- package/dist/reasoning/mechanism-design/types.js.map +1 -0
- package/dist/reasoning/mechanism-design/vcg.d.ts +29 -0
- package/dist/reasoning/mechanism-design/vcg.d.ts.map +1 -0
- package/dist/reasoning/mechanism-design/vcg.js +305 -0
- package/dist/reasoning/mechanism-design/vcg.js.map +1 -0
- package/dist/reasoning/probabilistic/distributions.d.ts +44 -0
- package/dist/reasoning/probabilistic/distributions.d.ts.map +1 -0
- package/dist/reasoning/probabilistic/distributions.js +207 -0
- package/dist/reasoning/probabilistic/distributions.js.map +1 -0
- package/dist/reasoning/probabilistic/examples.d.ts +31 -0
- package/dist/reasoning/probabilistic/examples.d.ts.map +1 -0
- package/dist/reasoning/probabilistic/examples.js +85 -0
- package/dist/reasoning/probabilistic/examples.js.map +1 -0
- package/dist/reasoning/probabilistic/index.d.ts +6 -0
- package/dist/reasoning/probabilistic/index.d.ts.map +1 -0
- package/dist/reasoning/probabilistic/index.js +42 -0
- package/dist/reasoning/probabilistic/index.js.map +1 -0
- package/dist/reasoning/probabilistic/inference.d.ts +45 -0
- package/dist/reasoning/probabilistic/inference.d.ts.map +1 -0
- package/dist/reasoning/probabilistic/inference.js +579 -0
- package/dist/reasoning/probabilistic/inference.js.map +1 -0
- package/dist/reasoning/probabilistic/types.d.ts +153 -0
- package/dist/reasoning/probabilistic/types.d.ts.map +1 -0
- package/dist/reasoning/probabilistic/types.js +37 -0
- package/dist/reasoning/probabilistic/types.js.map +1 -0
- package/dist/solver/smt-z3/index.d.ts +3 -0
- package/dist/solver/smt-z3/index.d.ts.map +1 -0
- package/dist/solver/smt-z3/index.js +11 -0
- package/dist/solver/smt-z3/index.js.map +1 -0
- package/dist/solver/smt-z3/types.d.ts +52 -0
- package/dist/solver/smt-z3/types.d.ts.map +1 -0
- package/dist/solver/smt-z3/types.js +6 -0
- package/dist/solver/smt-z3/types.js.map +1 -0
- package/dist/solver/smt-z3/z3-wasm-backend.d.ts +88 -0
- package/dist/solver/smt-z3/z3-wasm-backend.d.ts.map +1 -0
- package/dist/solver/smt-z3/z3-wasm-backend.js +437 -0
- package/dist/solver/smt-z3/z3-wasm-backend.js.map +1 -0
- package/dist/tests/reasoning/combinatorial-games/combinatorial-games.test.d.ts +2 -0
- package/dist/tests/reasoning/combinatorial-games/combinatorial-games.test.d.ts.map +1 -0
- package/dist/tests/reasoning/combinatorial-games/combinatorial-games.test.js +203 -0
- package/dist/tests/reasoning/combinatorial-games/combinatorial-games.test.js.map +1 -0
- package/dist/tests/reasoning/mechanism-design/mechanism-design.test.d.ts +2 -0
- package/dist/tests/reasoning/mechanism-design/mechanism-design.test.d.ts.map +1 -0
- package/dist/tests/reasoning/mechanism-design/mechanism-design.test.js +290 -0
- package/dist/tests/reasoning/mechanism-design/mechanism-design.test.js.map +1 -0
- package/dist/tests/reasoning/probabilistic/probabilistic.test.d.ts +2 -0
- package/dist/tests/reasoning/probabilistic/probabilistic.test.d.ts.map +1 -0
- package/dist/tests/reasoning/probabilistic/probabilistic.test.js +370 -0
- package/dist/tests/reasoning/probabilistic/probabilistic.test.js.map +1 -0
- package/dist/tests/solver/smt-z3/z3-wasm-backend.test.d.ts +2 -0
- package/dist/tests/solver/smt-z3/z3-wasm-backend.test.d.ts.map +1 -0
- package/dist/tests/solver/smt-z3/z3-wasm-backend.test.js +394 -0
- package/dist/tests/solver/smt-z3/z3-wasm-backend.test.js.map +1 -0
- package/dist/tests/tooling/proof-guidance/features.test.d.ts +2 -0
- package/dist/tests/tooling/proof-guidance/features.test.d.ts.map +1 -0
- package/dist/tests/tooling/proof-guidance/features.test.js +72 -0
- package/dist/tests/tooling/proof-guidance/features.test.js.map +1 -0
- package/dist/tests/tooling/proof-guidance/model.test.d.ts +2 -0
- package/dist/tests/tooling/proof-guidance/model.test.d.ts.map +1 -0
- package/dist/tests/tooling/proof-guidance/model.test.js +165 -0
- package/dist/tests/tooling/proof-guidance/model.test.js.map +1 -0
- package/dist/tests/tooling/proof-guidance/search.test.d.ts +2 -0
- package/dist/tests/tooling/proof-guidance/search.test.d.ts.map +1 -0
- package/dist/tests/tooling/proof-guidance/search.test.js +238 -0
- package/dist/tests/tooling/proof-guidance/search.test.js.map +1 -0
- package/dist/tests/type-theory/cubical/cubical.test.d.ts +2 -0
- package/dist/tests/type-theory/cubical/cubical.test.d.ts.map +1 -0
- package/dist/tests/type-theory/cubical/cubical.test.js +207 -0
- package/dist/tests/type-theory/cubical/cubical.test.js.map +1 -0
- package/dist/tooling/proof-guidance/features.d.ts +10 -0
- package/dist/tooling/proof-guidance/features.d.ts.map +1 -0
- package/dist/tooling/proof-guidance/features.js +97 -0
- package/dist/tooling/proof-guidance/features.js.map +1 -0
- package/dist/tooling/proof-guidance/index.d.ts +5 -0
- package/dist/tooling/proof-guidance/index.d.ts.map +1 -0
- package/dist/tooling/proof-guidance/index.js +25 -0
- package/dist/tooling/proof-guidance/index.js.map +1 -0
- package/dist/tooling/proof-guidance/model.d.ts +42 -0
- package/dist/tooling/proof-guidance/model.d.ts.map +1 -0
- package/dist/tooling/proof-guidance/model.js +149 -0
- package/dist/tooling/proof-guidance/model.js.map +1 -0
- package/dist/tooling/proof-guidance/search.d.ts +7 -0
- package/dist/tooling/proof-guidance/search.d.ts.map +1 -0
- package/dist/tooling/proof-guidance/search.js +102 -0
- package/dist/tooling/proof-guidance/search.js.map +1 -0
- package/dist/tooling/proof-guidance/types.d.ts +77 -0
- package/dist/tooling/proof-guidance/types.d.ts.map +1 -0
- package/dist/tooling/proof-guidance/types.js +8 -0
- package/dist/tooling/proof-guidance/types.js.map +1 -0
- package/dist/type-theory/cubical/equality.d.ts +4 -0
- package/dist/type-theory/cubical/equality.d.ts.map +1 -0
- package/dist/type-theory/cubical/equality.js +78 -0
- package/dist/type-theory/cubical/equality.js.map +1 -0
- package/dist/type-theory/cubical/index.d.ts +14 -0
- package/dist/type-theory/cubical/index.d.ts.map +1 -0
- package/dist/type-theory/cubical/index.js +71 -0
- package/dist/type-theory/cubical/index.js.map +1 -0
- package/dist/type-theory/cubical/infer.d.ts +18 -0
- package/dist/type-theory/cubical/infer.d.ts.map +1 -0
- package/dist/type-theory/cubical/infer.js +241 -0
- package/dist/type-theory/cubical/infer.js.map +1 -0
- package/dist/type-theory/cubical/interval.d.ts +12 -0
- package/dist/type-theory/cubical/interval.d.ts.map +1 -0
- package/dist/type-theory/cubical/interval.js +118 -0
- package/dist/type-theory/cubical/interval.js.map +1 -0
- package/dist/type-theory/cubical/normalize.d.ts +5 -0
- package/dist/type-theory/cubical/normalize.d.ts.map +1 -0
- package/dist/type-theory/cubical/normalize.js +191 -0
- package/dist/type-theory/cubical/normalize.js.map +1 -0
- package/dist/type-theory/cubical/path-algebra.d.ts +12 -0
- package/dist/type-theory/cubical/path-algebra.d.ts.map +1 -0
- package/dist/type-theory/cubical/path-algebra.js +109 -0
- package/dist/type-theory/cubical/path-algebra.js.map +1 -0
- package/dist/type-theory/cubical/substitute.d.ts +3 -0
- package/dist/type-theory/cubical/substitute.d.ts.map +1 -0
- package/dist/type-theory/cubical/substitute.js +109 -0
- package/dist/type-theory/cubical/substitute.js.map +1 -0
- package/dist/type-theory/cubical/types.d.ts +77 -0
- package/dist/type-theory/cubical/types.d.ts.map +1 -0
- package/dist/type-theory/cubical/types.js +258 -0
- package/dist/type-theory/cubical/types.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// Single-item auctions: first/second-price sealed, English, Dutch
|
|
4
|
+
// ============================================================
|
|
5
|
+
//
|
|
6
|
+
// Convención: bids con valor <= 0 se ignoran (no participa). Si no hay
|
|
7
|
+
// bidders válidos, devolvemos { winner: '', payment: 0 }. Empates se
|
|
8
|
+
// rompen lexicográficamente por id (determinista, testeable).
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.firstPriceSealed = firstPriceSealed;
|
|
11
|
+
exports.secondPriceSealed = secondPriceSealed;
|
|
12
|
+
exports.englishAuction = englishAuction;
|
|
13
|
+
exports.dutchAuction = dutchAuction;
|
|
14
|
+
/** Tie-breaking determinista: max bid, ties por id ascendente. */
|
|
15
|
+
function pickWinner(bids) {
|
|
16
|
+
let winner = '';
|
|
17
|
+
let bestBid = -Infinity;
|
|
18
|
+
// Orden lexicográfico de ids para empates reproducibles.
|
|
19
|
+
const ids = [...bids.keys()].sort();
|
|
20
|
+
for (const id of ids) {
|
|
21
|
+
const b = bids.get(id) ?? 0;
|
|
22
|
+
if (b > bestBid) {
|
|
23
|
+
bestBid = b;
|
|
24
|
+
winner = id;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (bestBid <= 0 || winner === '')
|
|
28
|
+
return { winner: '', bid: 0 };
|
|
29
|
+
return { winner, bid: bestBid };
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* First-price sealed-bid: el ganador paga su propio bid.
|
|
33
|
+
*
|
|
34
|
+
* No es strategy-proof — el bidder racional shadea su bid bajo su
|
|
35
|
+
* valuation. Pero la regla es lo más simple del mundo.
|
|
36
|
+
*/
|
|
37
|
+
function firstPriceSealed(bids) {
|
|
38
|
+
const { winner, bid } = pickWinner(bids);
|
|
39
|
+
if (winner === '')
|
|
40
|
+
return { winner: '', payment: 0 };
|
|
41
|
+
return { winner, payment: bid };
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Second-price sealed-bid (Vickrey): el ganador paga el segundo bid más
|
|
45
|
+
* alto. Es DSIC: bidding truthful es dominante.
|
|
46
|
+
*
|
|
47
|
+
* Si solo hay un bidder válido, paga 0 (no hay segundo precio). Esa es
|
|
48
|
+
* la convención estándar; en variantes con reserve, el reserve actúa
|
|
49
|
+
* como segundo precio si no hay otro bidder por encima.
|
|
50
|
+
*/
|
|
51
|
+
function secondPriceSealed(bids) {
|
|
52
|
+
const ids = [...bids.keys()].sort();
|
|
53
|
+
if (ids.length === 0)
|
|
54
|
+
return { winner: '', payment: 0 };
|
|
55
|
+
// Localizamos el primero y segundo bid más alto.
|
|
56
|
+
let winner = '';
|
|
57
|
+
let first = -Infinity;
|
|
58
|
+
let second = 0;
|
|
59
|
+
for (const id of ids) {
|
|
60
|
+
const b = bids.get(id) ?? 0;
|
|
61
|
+
if (b > first) {
|
|
62
|
+
second = first === -Infinity ? 0 : first;
|
|
63
|
+
first = b;
|
|
64
|
+
winner = id;
|
|
65
|
+
}
|
|
66
|
+
else if (b > second) {
|
|
67
|
+
second = b;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (first <= 0 || winner === '')
|
|
71
|
+
return { winner: '', payment: 0 };
|
|
72
|
+
// Si no hubo "segundo" real (todos los otros 0 o ausentes), pagan 0.
|
|
73
|
+
if (second < 0)
|
|
74
|
+
second = 0;
|
|
75
|
+
return { winner, payment: second };
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* English ascending auction: simulamos un reloj que sube en pasos de
|
|
79
|
+
* `increment`. Cada bidder sigue activo mientras el precio no supere
|
|
80
|
+
* su valuation. Cuando solo queda 1 activo, termina y paga el precio
|
|
81
|
+
* actual.
|
|
82
|
+
*
|
|
83
|
+
* Bajo bidders racionales (cada uno dropea exactamente en su valuation),
|
|
84
|
+
* el resultado es equivalente a second-price (el ganador paga ~ segundo
|
|
85
|
+
* valor más alto, módulo `increment`).
|
|
86
|
+
*
|
|
87
|
+
* Implementación: en vez de simular reloj, calculamos directo:
|
|
88
|
+
* winner = bidder con max valuation
|
|
89
|
+
* payment = ceil(secondHighest / increment) * increment ≈ second + un step
|
|
90
|
+
*
|
|
91
|
+
* Para los tests usamos increment=1, lo que da payment ≈ second.
|
|
92
|
+
*/
|
|
93
|
+
function englishAuction(bids, increment) {
|
|
94
|
+
if (increment <= 0)
|
|
95
|
+
throw new Error('English auction increment must be > 0');
|
|
96
|
+
const ids = [...bids.keys()].sort();
|
|
97
|
+
if (ids.length === 0)
|
|
98
|
+
return { winner: '', payment: 0 };
|
|
99
|
+
let winner = '';
|
|
100
|
+
let first = -Infinity;
|
|
101
|
+
let second = 0;
|
|
102
|
+
for (const id of ids) {
|
|
103
|
+
const b = bids.get(id) ?? 0;
|
|
104
|
+
if (b > first) {
|
|
105
|
+
second = first === -Infinity ? 0 : first;
|
|
106
|
+
first = b;
|
|
107
|
+
winner = id;
|
|
108
|
+
}
|
|
109
|
+
else if (b > second) {
|
|
110
|
+
second = b;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (first <= 0 || winner === '')
|
|
114
|
+
return { winner: '', payment: 0 };
|
|
115
|
+
if (second < 0)
|
|
116
|
+
second = 0;
|
|
117
|
+
// El reloj cruzó el step inmediatamente sobre `second`. Si second cae
|
|
118
|
+
// exactamente en un múltiplo de increment, el segundo bidder dropea
|
|
119
|
+
// justo y el ganador paga `second`. Si no, paga el siguiente step.
|
|
120
|
+
let payment;
|
|
121
|
+
const steps = Math.floor(second / increment);
|
|
122
|
+
const onGrid = Math.abs(second - steps * increment) < 1e-9;
|
|
123
|
+
if (onGrid) {
|
|
124
|
+
payment = second;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
payment = (steps + 1) * increment;
|
|
128
|
+
}
|
|
129
|
+
if (payment > first)
|
|
130
|
+
payment = first;
|
|
131
|
+
return { winner, payment };
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Dutch descending auction: reloj baja desde `initialPrice` con pasos
|
|
135
|
+
* `decrement`. El primer bidder en aceptar (precio ≤ su valuation)
|
|
136
|
+
* gana y paga ese precio.
|
|
137
|
+
*
|
|
138
|
+
* Estratégicamente, Dutch ≡ first-price sealed: cada bidder elige a qué
|
|
139
|
+
* precio aceptar, equivalente a elegir su bid. Implementamos via
|
|
140
|
+
* simulación discreta.
|
|
141
|
+
*
|
|
142
|
+
* `bidders.get(id)` = valor máximo que el bidder está dispuesto a pagar
|
|
143
|
+
* (su bid efectivo en el equivalente sealed). El primero en alcanzar
|
|
144
|
+
* un precio ≤ a su bid gana.
|
|
145
|
+
*/
|
|
146
|
+
function dutchAuction(initialPrice, bidders, decrement) {
|
|
147
|
+
if (decrement <= 0)
|
|
148
|
+
throw new Error('Dutch auction decrement must be > 0');
|
|
149
|
+
if (initialPrice < 0)
|
|
150
|
+
throw new Error('Dutch auction initialPrice must be >= 0');
|
|
151
|
+
const ids = [...bidders.keys()].sort();
|
|
152
|
+
if (ids.length === 0)
|
|
153
|
+
return { winner: '', payment: 0 };
|
|
154
|
+
let price = initialPrice;
|
|
155
|
+
// Tolerancia para no caer en loops infinitos por floating-point.
|
|
156
|
+
const maxSteps = Math.ceil(initialPrice / decrement) + 1;
|
|
157
|
+
for (let step = 0; step <= maxSteps; step++) {
|
|
158
|
+
// Snapshot del precio actual; bidders elegibles = bid >= price.
|
|
159
|
+
let candidate = '';
|
|
160
|
+
let candidateBid = -Infinity;
|
|
161
|
+
for (const id of ids) {
|
|
162
|
+
const b = bidders.get(id) ?? 0;
|
|
163
|
+
if (b >= price - 1e-12 && b > candidateBid) {
|
|
164
|
+
candidateBid = b;
|
|
165
|
+
candidate = id;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
if (candidate !== '') {
|
|
169
|
+
// El primero en aceptar paga el precio actual (clamp a >= 0).
|
|
170
|
+
const payment = Math.max(0, price);
|
|
171
|
+
return { winner: candidate, payment };
|
|
172
|
+
}
|
|
173
|
+
price -= decrement;
|
|
174
|
+
if (price < 0)
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
return { winner: '', payment: 0 };
|
|
178
|
+
}
|
|
179
|
+
//# sourceMappingURL=auctions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auctions.js","sourceRoot":"","sources":["../../../src/reasoning/mechanism-design/auctions.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,kEAAkE;AAClE,+DAA+D;AAC/D,EAAE;AACF,uEAAuE;AACvE,qEAAqE;AACrE,8DAA8D;;AA2B9D,4CAIC;AAUD,8CAsBC;AAkBD,wCAkCC;AAeD,oCAiCC;AA/JD,kEAAkE;AAClE,SAAS,UAAU,CAAC,IAAyB;IAC3C,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,IAAI,OAAO,GAAG,CAAC,QAAQ,CAAC;IACxB,yDAAyD;IACzD,MAAM,GAAG,GAAG,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IACpC,KAAK,MAAM,EAAE,IAAI,GAAG,EAAE,CAAC;QACrB,MAAM,CAAC,GAAG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';
|
|
2
|
+
export { vcgMechanism, socialWelfare, isStrategyProof } from './vcg';
|
|
3
|
+
export { firstPriceSealed, secondPriceSealed, englishAuction, dutchAuction } from './auctions';
|
|
4
|
+
export { myersonOptimal, virtualValuation, findReserve, expectedRevenue, sampleFromDistribution, uniformDistribution, } from './myerson';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/reasoning/mechanism-design/index.ts"],"names":[],"mappings":"AAoBA,YAAY,EACV,KAAK,EACL,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,SAAS,CAAC;AAEjB,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,OAAO,CAAC;AAErE,OAAO,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAE/F,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,WAAW,EACX,eAAe,EACf,sBAAsB,EACtB,mBAAmB,GACpB,MAAM,WAAW,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// Mechanism design — barrel público
|
|
4
|
+
// ============================================================
|
|
5
|
+
//
|
|
6
|
+
// Implementación de los mecanismos canónicos de la teoría:
|
|
7
|
+
//
|
|
8
|
+
// - VCG (Vickrey-Clarke-Groves): allocation que maximiza welfare,
|
|
9
|
+
// pagos por externalidad. DSIC.
|
|
10
|
+
// - First-price sealed-bid: ganador paga su bid.
|
|
11
|
+
// - Second-price sealed-bid (Vickrey): ganador paga el segundo
|
|
12
|
+
// precio. DSIC. Coincide con VCG para 1 item.
|
|
13
|
+
// - English ascending: reloj sube, sale el último parado.
|
|
14
|
+
// - Dutch descending: reloj baja, gana el primero en aceptar.
|
|
15
|
+
// - Myerson optimal auction: maximiza expected revenue via virtual
|
|
16
|
+
// valuations + reserve price.
|
|
17
|
+
//
|
|
18
|
+
// Helpers:
|
|
19
|
+
// - socialWelfare, isStrategyProof (empírico)
|
|
20
|
+
// - virtualValuation, expectedRevenue (Monte Carlo)
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
exports.uniformDistribution = exports.sampleFromDistribution = exports.expectedRevenue = exports.findReserve = exports.virtualValuation = exports.myersonOptimal = exports.dutchAuction = exports.englishAuction = exports.secondPriceSealed = exports.firstPriceSealed = exports.isStrategyProof = exports.socialWelfare = exports.vcgMechanism = void 0;
|
|
23
|
+
var vcg_1 = require("./vcg");
|
|
24
|
+
Object.defineProperty(exports, "vcgMechanism", { enumerable: true, get: function () { return vcg_1.vcgMechanism; } });
|
|
25
|
+
Object.defineProperty(exports, "socialWelfare", { enumerable: true, get: function () { return vcg_1.socialWelfare; } });
|
|
26
|
+
Object.defineProperty(exports, "isStrategyProof", { enumerable: true, get: function () { return vcg_1.isStrategyProof; } });
|
|
27
|
+
var auctions_1 = require("./auctions");
|
|
28
|
+
Object.defineProperty(exports, "firstPriceSealed", { enumerable: true, get: function () { return auctions_1.firstPriceSealed; } });
|
|
29
|
+
Object.defineProperty(exports, "secondPriceSealed", { enumerable: true, get: function () { return auctions_1.secondPriceSealed; } });
|
|
30
|
+
Object.defineProperty(exports, "englishAuction", { enumerable: true, get: function () { return auctions_1.englishAuction; } });
|
|
31
|
+
Object.defineProperty(exports, "dutchAuction", { enumerable: true, get: function () { return auctions_1.dutchAuction; } });
|
|
32
|
+
var myerson_1 = require("./myerson");
|
|
33
|
+
Object.defineProperty(exports, "myersonOptimal", { enumerable: true, get: function () { return myerson_1.myersonOptimal; } });
|
|
34
|
+
Object.defineProperty(exports, "virtualValuation", { enumerable: true, get: function () { return myerson_1.virtualValuation; } });
|
|
35
|
+
Object.defineProperty(exports, "findReserve", { enumerable: true, get: function () { return myerson_1.findReserve; } });
|
|
36
|
+
Object.defineProperty(exports, "expectedRevenue", { enumerable: true, get: function () { return myerson_1.expectedRevenue; } });
|
|
37
|
+
Object.defineProperty(exports, "sampleFromDistribution", { enumerable: true, get: function () { return myerson_1.sampleFromDistribution; } });
|
|
38
|
+
Object.defineProperty(exports, "uniformDistribution", { enumerable: true, get: function () { return myerson_1.uniformDistribution; } });
|
|
39
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/reasoning/mechanism-design/index.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,oCAAoC;AACpC,+DAA+D;AAC/D,EAAE;AACF,2DAA2D;AAC3D,EAAE;AACF,oEAAoE;AACpE,oCAAoC;AACpC,mDAAmD;AACnD,iEAAiE;AACjE,kDAAkD;AAClD,4DAA4D;AAC5D,gEAAgE;AAChE,qEAAqE;AACrE,kCAAkC;AAClC,EAAE;AACF,WAAW;AACX,gDAAgD;AAChD,sDAAsD;;;AAUtD,6BAAqE;AAA5D,mGAAA,YAAY,OAAA;AAAE,oGAAA,aAAa,OAAA;AAAE,sGAAA,eAAe,OAAA;AAErD,uCAA+F;AAAtF,4GAAA,gBAAgB,OAAA;AAAE,6GAAA,iBAAiB,OAAA;AAAE,0GAAA,cAAc,OAAA;AAAE,wGAAA,YAAY,OAAA;AAE1E,qCAOmB;AANjB,yGAAA,cAAc,OAAA;AACd,2GAAA,gBAAgB,OAAA;AAChB,sGAAA,WAAW,OAAA;AACX,0GAAA,eAAe,OAAA;AACf,iHAAA,sBAAsB,OAAA;AACtB,8GAAA,mBAAmB,OAAA"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import type { BidderDistribution, AuctionResult } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* Virtual valuation φ(v) = v - (1 - F(v)) / f(v).
|
|
4
|
+
*
|
|
5
|
+
* Si f(v) ≈ 0 retornamos +Infinity (límite del término penalty).
|
|
6
|
+
* Si v cae fuera del dominio, devolvemos -Infinity (no participa).
|
|
7
|
+
*/
|
|
8
|
+
export declare function virtualValuation(v: number, dist: BidderDistribution): number;
|
|
9
|
+
/**
|
|
10
|
+
* Resuelve φ(r) = 0 por bisección en el dominio de la distribución.
|
|
11
|
+
*
|
|
12
|
+
* Si φ(lo) >= 0, devuelve lo. Si φ(hi) <= 0, devuelve hi. Si no, busca
|
|
13
|
+
* con tolerancia 1e-8 en 80 iteraciones.
|
|
14
|
+
*
|
|
15
|
+
* Asume regularidad de la distribución (φ monótona creciente). En
|
|
16
|
+
* uniform[0,1]: φ(v) = 2v - 1, raíz en 1/2. ✔
|
|
17
|
+
*/
|
|
18
|
+
export declare function findReserve(dist: BidderDistribution): number;
|
|
19
|
+
/**
|
|
20
|
+
* Myerson optimal auction (single-item).
|
|
21
|
+
*
|
|
22
|
+
* - Si todos los φ_i(bid_i) son negativos → no se vende. winner='',
|
|
23
|
+
* payment=0, reserve = φ_i^(-1)(0) del primer bidder (referencia).
|
|
24
|
+
*
|
|
25
|
+
* - Si el ganador es bidder i (max φ), paga el menor v' tal que
|
|
26
|
+
* reportar v' lo habría hecho ganar:
|
|
27
|
+
*
|
|
28
|
+
* paymentValue = max( reserve_i, min_v { v : φ_i(v) >= max_{j≠i} φ_j(bid_j) } )
|
|
29
|
+
*
|
|
30
|
+
* En el caso IID con simétria, esto es:
|
|
31
|
+
* paymentValue = max( reserve, secondHighestBid )
|
|
32
|
+
*
|
|
33
|
+
* que es exactamente Vickrey con reserve.
|
|
34
|
+
*/
|
|
35
|
+
export declare function myersonOptimal(bids: Map<string, number>, distributions: Map<string, BidderDistribution>): {
|
|
36
|
+
winner: string;
|
|
37
|
+
payment: number;
|
|
38
|
+
reserve: number;
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Muestrea una valuation de una distribución por inverse-CDF
|
|
42
|
+
* sampling. Usamos bisección sobre F.
|
|
43
|
+
*/
|
|
44
|
+
export declare function sampleFromDistribution(dist: BidderDistribution, u: number): number;
|
|
45
|
+
/**
|
|
46
|
+
* Expected revenue de un mechanism via Monte Carlo: muestreamos
|
|
47
|
+
* `samples` perfiles de bids (cada bidder draw de su distribución
|
|
48
|
+
* independientemente, asumiendo truthful bidding para 2nd-price /
|
|
49
|
+
* Myerson, o equilibrium bidding aproximado para 1st-price), corremos
|
|
50
|
+
* el mechanism y promediamos el payment del ganador.
|
|
51
|
+
*
|
|
52
|
+
* Nota: para 1st-price con IID uniform[0,1] y n bidders, el bid
|
|
53
|
+
* de equilibrio es b(v) = (n-1)/n · v. El caller debe pasar un
|
|
54
|
+
* mechanism que ya implemente ese mapping si quiere comparar contra
|
|
55
|
+
* 2nd-price truthful.
|
|
56
|
+
*/
|
|
57
|
+
export declare function expectedRevenue(mechanism: (bids: Map<string, number>) => AuctionResult, distributions: Map<string, BidderDistribution>, samples?: number): number;
|
|
58
|
+
/**
|
|
59
|
+
* Helper: distribución uniform sobre [a, b]. Útil para tests.
|
|
60
|
+
* (No exportada en index — solo helper interno aquí; los tests
|
|
61
|
+
* pueden importarlo directamente.)
|
|
62
|
+
*/
|
|
63
|
+
export declare function uniformDistribution(a: number, b: number): BidderDistribution;
|
|
64
|
+
//# sourceMappingURL=myerson.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"myerson.d.ts","sourceRoot":"","sources":["../../../src/reasoning/mechanism-design/myerson.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAEjE;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,GAAG,MAAM,CAW5E;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,kBAAkB,GAAG,MAAM,CAiB5D;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,cAAc,CAC5B,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,EACzB,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,GAC7C;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAoDtD;AAyBD;;;GAGG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE,kBAAkB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAclF;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,eAAe,CAC7B,SAAS,EAAE,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,aAAa,EACvD,aAAa,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,CAAC,EAC9C,OAAO,GAAE,MAAa,GACrB,MAAM,CAeR;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,kBAAkB,CAe5E"}
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// Myerson optimal auction + revenue equivalence
|
|
4
|
+
// ============================================================
|
|
5
|
+
//
|
|
6
|
+
// Myerson (1981): para vender 1 item a `n` bidders independientes con
|
|
7
|
+
// valuations privadas de distribuciones regulares F_i, el mechanism
|
|
8
|
+
// óptimo en expected revenue es:
|
|
9
|
+
//
|
|
10
|
+
// 1. Calcular virtual valuation φ_i(v) = v - (1 - F_i(v)) / f_i(v).
|
|
11
|
+
// 2. Asignar al bidder con MAYOR φ_i (si > 0, si no, no asignar →
|
|
12
|
+
// reserve price implícito r_i tal que φ_i(r_i) = 0).
|
|
13
|
+
// 3. Cobrar al ganador el menor bid que lo habría hecho ganar
|
|
14
|
+
// (Vickrey-style payment sobre virtual valuations).
|
|
15
|
+
//
|
|
16
|
+
// Para distribuciones simétricas (todos los bidders i.i.d. con misma
|
|
17
|
+
// F), φ es la misma función para todos; el mechanism colapsa a una
|
|
18
|
+
// second-price auction con reserve price r = φ^(-1)(0).
|
|
19
|
+
//
|
|
20
|
+
// Revenue equivalence theorem: en cualquier mechanism que (a) asigne
|
|
21
|
+
// al bidder con mayor valuation y (b) dé utilidad 0 al bidder con
|
|
22
|
+
// valuation 0 ("regularity boundary"), el expected revenue es el
|
|
23
|
+
// mismo. → 1st-price y 2nd-price tienen igual revenue esperado bajo
|
|
24
|
+
// IID.
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.virtualValuation = virtualValuation;
|
|
27
|
+
exports.findReserve = findReserve;
|
|
28
|
+
exports.myersonOptimal = myersonOptimal;
|
|
29
|
+
exports.sampleFromDistribution = sampleFromDistribution;
|
|
30
|
+
exports.expectedRevenue = expectedRevenue;
|
|
31
|
+
exports.uniformDistribution = uniformDistribution;
|
|
32
|
+
/**
|
|
33
|
+
* Virtual valuation φ(v) = v - (1 - F(v)) / f(v).
|
|
34
|
+
*
|
|
35
|
+
* Si f(v) ≈ 0 retornamos +Infinity (límite del término penalty).
|
|
36
|
+
* Si v cae fuera del dominio, devolvemos -Infinity (no participa).
|
|
37
|
+
*/
|
|
38
|
+
function virtualValuation(v, dist) {
|
|
39
|
+
const [lo, hi] = dist.domain;
|
|
40
|
+
if (v < lo || v > hi)
|
|
41
|
+
return -Infinity;
|
|
42
|
+
const f = dist.pdf(v);
|
|
43
|
+
if (!Number.isFinite(f) || Math.abs(f) < 1e-15) {
|
|
44
|
+
// En el borde superior, F(v) = 1 → (1-F)/f = 0/0; tomamos v como límite.
|
|
45
|
+
if (Math.abs(1 - dist.cdf(v)) < 1e-12)
|
|
46
|
+
return v;
|
|
47
|
+
return v;
|
|
48
|
+
}
|
|
49
|
+
const F = dist.cdf(v);
|
|
50
|
+
return v - (1 - F) / f;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Resuelve φ(r) = 0 por bisección en el dominio de la distribución.
|
|
54
|
+
*
|
|
55
|
+
* Si φ(lo) >= 0, devuelve lo. Si φ(hi) <= 0, devuelve hi. Si no, busca
|
|
56
|
+
* con tolerancia 1e-8 en 80 iteraciones.
|
|
57
|
+
*
|
|
58
|
+
* Asume regularidad de la distribución (φ monótona creciente). En
|
|
59
|
+
* uniform[0,1]: φ(v) = 2v - 1, raíz en 1/2. ✔
|
|
60
|
+
*/
|
|
61
|
+
function findReserve(dist) {
|
|
62
|
+
const [lo, hi] = dist.domain;
|
|
63
|
+
const phiLo = virtualValuation(lo, dist);
|
|
64
|
+
const phiHi = virtualValuation(hi, dist);
|
|
65
|
+
if (phiLo >= 0)
|
|
66
|
+
return lo;
|
|
67
|
+
if (phiHi <= 0)
|
|
68
|
+
return hi;
|
|
69
|
+
let l = lo;
|
|
70
|
+
let h = hi;
|
|
71
|
+
for (let i = 0; i < 80; i++) {
|
|
72
|
+
const m = (l + h) / 2;
|
|
73
|
+
const phi = virtualValuation(m, dist);
|
|
74
|
+
if (phi > 0)
|
|
75
|
+
h = m;
|
|
76
|
+
else
|
|
77
|
+
l = m;
|
|
78
|
+
if (h - l < 1e-9)
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
return (l + h) / 2;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Myerson optimal auction (single-item).
|
|
85
|
+
*
|
|
86
|
+
* - Si todos los φ_i(bid_i) son negativos → no se vende. winner='',
|
|
87
|
+
* payment=0, reserve = φ_i^(-1)(0) del primer bidder (referencia).
|
|
88
|
+
*
|
|
89
|
+
* - Si el ganador es bidder i (max φ), paga el menor v' tal que
|
|
90
|
+
* reportar v' lo habría hecho ganar:
|
|
91
|
+
*
|
|
92
|
+
* paymentValue = max( reserve_i, min_v { v : φ_i(v) >= max_{j≠i} φ_j(bid_j) } )
|
|
93
|
+
*
|
|
94
|
+
* En el caso IID con simétria, esto es:
|
|
95
|
+
* paymentValue = max( reserve, secondHighestBid )
|
|
96
|
+
*
|
|
97
|
+
* que es exactamente Vickrey con reserve.
|
|
98
|
+
*/
|
|
99
|
+
function myersonOptimal(bids, distributions) {
|
|
100
|
+
const ids = [...bids.keys()].sort();
|
|
101
|
+
if (ids.length === 0) {
|
|
102
|
+
return { winner: '', payment: 0, reserve: 0 };
|
|
103
|
+
}
|
|
104
|
+
// Buscamos el bidder con mayor virtual valuation positivo.
|
|
105
|
+
let winner = '';
|
|
106
|
+
let bestPhi = 0; // estricto > 0 — el reserve viene de φ(r) = 0
|
|
107
|
+
let secondPhi = 0;
|
|
108
|
+
for (const id of ids) {
|
|
109
|
+
const b = bids.get(id) ?? 0;
|
|
110
|
+
const dist = distributions.get(id);
|
|
111
|
+
if (!dist)
|
|
112
|
+
continue;
|
|
113
|
+
const phi = virtualValuation(b, dist);
|
|
114
|
+
if (phi > bestPhi) {
|
|
115
|
+
secondPhi = bestPhi;
|
|
116
|
+
bestPhi = phi;
|
|
117
|
+
winner = id;
|
|
118
|
+
}
|
|
119
|
+
else if (phi > secondPhi) {
|
|
120
|
+
secondPhi = phi;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// Reserve de referencia: del primer bidder (todos los i.i.d. comparten).
|
|
124
|
+
const firstDist = distributions.get(ids[0]);
|
|
125
|
+
if (!firstDist) {
|
|
126
|
+
return { winner: '', payment: 0, reserve: 0 };
|
|
127
|
+
}
|
|
128
|
+
const referenceReserve = findReserve(firstDist);
|
|
129
|
+
if (winner === '') {
|
|
130
|
+
return { winner: '', payment: 0, reserve: referenceReserve };
|
|
131
|
+
}
|
|
132
|
+
const winnerDist = distributions.get(winner);
|
|
133
|
+
if (!winnerDist) {
|
|
134
|
+
return { winner: '', payment: 0, reserve: referenceReserve };
|
|
135
|
+
}
|
|
136
|
+
const winnerReserve = findReserve(winnerDist);
|
|
137
|
+
// Pago: el menor valor v* tal que φ_winner(v*) >= max(secondPhi, 0).
|
|
138
|
+
// En IID: φ es monótona, así que invertimos por bisección.
|
|
139
|
+
const targetPhi = Math.max(secondPhi, 0);
|
|
140
|
+
let payment = invertVirtual(winnerDist, targetPhi);
|
|
141
|
+
if (payment < winnerReserve)
|
|
142
|
+
payment = winnerReserve;
|
|
143
|
+
// Sanity: el pago no puede exceder el bid del ganador.
|
|
144
|
+
const winnerBid = bids.get(winner) ?? 0;
|
|
145
|
+
if (payment > winnerBid)
|
|
146
|
+
payment = winnerBid;
|
|
147
|
+
return { winner, payment, reserve: winnerReserve };
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Inverte φ: encuentra v* tal que φ(v*) = target. Asume regularidad.
|
|
151
|
+
* Si target <= φ(lo), devuelve lo. Si target >= φ(hi), devuelve hi.
|
|
152
|
+
*/
|
|
153
|
+
function invertVirtual(dist, target) {
|
|
154
|
+
const [lo, hi] = dist.domain;
|
|
155
|
+
const phiLo = virtualValuation(lo, dist);
|
|
156
|
+
const phiHi = virtualValuation(hi, dist);
|
|
157
|
+
if (target <= phiLo)
|
|
158
|
+
return lo;
|
|
159
|
+
if (target >= phiHi)
|
|
160
|
+
return hi;
|
|
161
|
+
let l = lo;
|
|
162
|
+
let h = hi;
|
|
163
|
+
for (let i = 0; i < 80; i++) {
|
|
164
|
+
const m = (l + h) / 2;
|
|
165
|
+
const phi = virtualValuation(m, dist);
|
|
166
|
+
if (phi >= target)
|
|
167
|
+
h = m;
|
|
168
|
+
else
|
|
169
|
+
l = m;
|
|
170
|
+
if (h - l < 1e-9)
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
173
|
+
return (l + h) / 2;
|
|
174
|
+
}
|
|
175
|
+
/**
|
|
176
|
+
* Muestrea una valuation de una distribución por inverse-CDF
|
|
177
|
+
* sampling. Usamos bisección sobre F.
|
|
178
|
+
*/
|
|
179
|
+
function sampleFromDistribution(dist, u) {
|
|
180
|
+
// u ∈ [0,1]. Encontrar v con F(v) = u.
|
|
181
|
+
const [lo, hi] = dist.domain;
|
|
182
|
+
if (u <= 0)
|
|
183
|
+
return lo;
|
|
184
|
+
if (u >= 1)
|
|
185
|
+
return hi;
|
|
186
|
+
let l = lo;
|
|
187
|
+
let h = hi;
|
|
188
|
+
for (let i = 0; i < 80; i++) {
|
|
189
|
+
const m = (l + h) / 2;
|
|
190
|
+
if (dist.cdf(m) > u)
|
|
191
|
+
h = m;
|
|
192
|
+
else
|
|
193
|
+
l = m;
|
|
194
|
+
if (h - l < 1e-9)
|
|
195
|
+
break;
|
|
196
|
+
}
|
|
197
|
+
return (l + h) / 2;
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Expected revenue de un mechanism via Monte Carlo: muestreamos
|
|
201
|
+
* `samples` perfiles de bids (cada bidder draw de su distribución
|
|
202
|
+
* independientemente, asumiendo truthful bidding para 2nd-price /
|
|
203
|
+
* Myerson, o equilibrium bidding aproximado para 1st-price), corremos
|
|
204
|
+
* el mechanism y promediamos el payment del ganador.
|
|
205
|
+
*
|
|
206
|
+
* Nota: para 1st-price con IID uniform[0,1] y n bidders, el bid
|
|
207
|
+
* de equilibrio es b(v) = (n-1)/n · v. El caller debe pasar un
|
|
208
|
+
* mechanism que ya implemente ese mapping si quiere comparar contra
|
|
209
|
+
* 2nd-price truthful.
|
|
210
|
+
*/
|
|
211
|
+
function expectedRevenue(mechanism, distributions, samples = 5000) {
|
|
212
|
+
const ids = [...distributions.keys()].sort();
|
|
213
|
+
let totalRevenue = 0;
|
|
214
|
+
for (let s = 0; s < samples; s++) {
|
|
215
|
+
const bids = new Map();
|
|
216
|
+
for (const id of ids) {
|
|
217
|
+
const dist = distributions.get(id);
|
|
218
|
+
if (!dist)
|
|
219
|
+
continue;
|
|
220
|
+
const u = Math.random();
|
|
221
|
+
bids.set(id, sampleFromDistribution(dist, u));
|
|
222
|
+
}
|
|
223
|
+
const r = mechanism(bids);
|
|
224
|
+
totalRevenue += r.payment;
|
|
225
|
+
}
|
|
226
|
+
return totalRevenue / samples;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Helper: distribución uniform sobre [a, b]. Útil para tests.
|
|
230
|
+
* (No exportada en index — solo helper interno aquí; los tests
|
|
231
|
+
* pueden importarlo directamente.)
|
|
232
|
+
*/
|
|
233
|
+
function uniformDistribution(a, b) {
|
|
234
|
+
if (b <= a)
|
|
235
|
+
throw new Error('uniformDistribution: b must be > a');
|
|
236
|
+
const span = b - a;
|
|
237
|
+
return {
|
|
238
|
+
domain: [a, b],
|
|
239
|
+
cdf: (v) => {
|
|
240
|
+
if (v <= a)
|
|
241
|
+
return 0;
|
|
242
|
+
if (v >= b)
|
|
243
|
+
return 1;
|
|
244
|
+
return (v - a) / span;
|
|
245
|
+
},
|
|
246
|
+
pdf: (v) => {
|
|
247
|
+
if (v < a || v > b)
|
|
248
|
+
return 0;
|
|
249
|
+
return 1 / span;
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
//# sourceMappingURL=myerson.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"myerson.js","sourceRoot":"","sources":["../../../src/reasoning/mechanism-design/myerson.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,gDAAgD;AAChD,+DAA+D;AAC/D,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,iCAAiC;AACjC,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,0DAA0D;AAC1D,gEAAgE;AAChE,yDAAyD;AACzD,EAAE;AACF,qEAAqE;AACrE,mEAAmE;AACnE,wDAAwD;AACxD,EAAE;AACF,qEAAqE;AACrE,kEAAkE;AAClE,iEAAiE;AACjE,oEAAoE;AACpE,OAAO;;AAUP,4CAWC;AAWD,kCAiBC;AAkBD,wCAuDC;AA6BD,wDAcC;AAcD,0CAmBC;AAOD,kDAeC;AAxND;;;;;GAKG;AACH,SAAgB,gBAAgB,CAAC,CAAS,EAAE,IAAwB;IAClE,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC;IAC7B,IAAI,CAAC,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE;QAAE,OAAO,CAAC,QAAQ,CA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AAI,CAAC,IAAI,CAAC;QAAE,MAAM,IAAI,KAAK,CAAC,oCAAoC,CAAC,CAAC;IAClE,MAAM,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;IACnB,OAAO;QACL,MAAM,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;QACd,GAAG,EAAE,CAAC,CAAS,EAAE,EAAE;YACjB,IAAI,CAAC,IAAI,CAAC;gBAAE,OAAO,CAAC,CAAC;YACrB,IAAI,CAAC,IAAI,CAAC;gBAAE,OAAO,CAAC,CAAC;YACrB,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;QACxB,CAAC;QACD,GAAG,EAAE,CAAC,CAAS,EAAE,EAAE;YACjB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC;gBAAE,OAAO,CAAC,CAAC;YAC7B,OAAO,CAAC,GAAG,IAAI,CAAC;QAClB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Un agente con valuation sobre outcomes. Cada outcome se identifica
|
|
3
|
+
* con un string (típicamente itemId, pero puede codificar bundles
|
|
4
|
+
* para combinatorial auctions, e.g. "A+B").
|
|
5
|
+
*/
|
|
6
|
+
export interface Agent {
|
|
7
|
+
id: string;
|
|
8
|
+
/** valuation.get(outcome) = utilidad si recibe ese outcome. Default 0 si missing. */
|
|
9
|
+
valuation: Map<string, number>;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Resultado de un mechanism: quién se queda con qué y cuánto paga.
|
|
13
|
+
*/
|
|
14
|
+
export interface MechanismOutcome {
|
|
15
|
+
/** allocation.get(agentId) = item que recibe (o undefined si no recibe). */
|
|
16
|
+
allocation: Map<string, string>;
|
|
17
|
+
/** payments.get(agentId) = pago del agente al mechanism (>= 0 típicamente). */
|
|
18
|
+
payments: Map<string, number>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Resultado de una single-item auction.
|
|
22
|
+
*/
|
|
23
|
+
export interface AuctionResult {
|
|
24
|
+
/** Id del ganador (o '' si nadie supera el reserve / no hay bids). */
|
|
25
|
+
winner: string;
|
|
26
|
+
/** Pago del ganador. 0 si no hubo ganador. */
|
|
27
|
+
payment: number;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Auction con bids sealed (cada bidder reporta un valor secreto).
|
|
31
|
+
*/
|
|
32
|
+
export interface SealedBidAuction {
|
|
33
|
+
bids: Map<string, number>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Distribución (i.i.d. por bidder) sobre la valuation. Necesitamos CDF
|
|
37
|
+
* y PDF en cerrado para Myerson; el dominio acota el soporte.
|
|
38
|
+
*/
|
|
39
|
+
export interface BidderDistribution {
|
|
40
|
+
cdf: (v: number) => number;
|
|
41
|
+
pdf: (v: number) => number;
|
|
42
|
+
domain: [number, number];
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/reasoning/mechanism-design/types.ts"],"names":[],"mappings":"AAoBA;;;;GAIG;AACH,MAAM,WAAW,KAAK;IACpB,EAAE,EAAE,MAAM,CAAC;IACX,qFAAqF;IACrF,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAChC;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,4EAA4E;IAC5E,UAAU,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,+EAA+E;IAC/E,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,sEAAsE;IACtE,MAAM,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC3B;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAC3B,GAAG,EAAE,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;IAC3B,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAC1B"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// ============================================================
|
|
3
|
+
// Mechanism design — tipos compartidos
|
|
4
|
+
// ============================================================
|
|
5
|
+
//
|
|
6
|
+
// Modelamos mechanism design discreto sobre un conjunto finito de
|
|
7
|
+
// outcomes (típicamente: asignar ítems a agentes). Cada agente reporta
|
|
8
|
+
// una valuation `Map<outcomeId, number>`. El mechanism elige una
|
|
9
|
+
// allocation y cobra pagos.
|
|
10
|
+
//
|
|
11
|
+
// El bundle de un agente en una allocation es el conjunto de outcomes
|
|
12
|
+
// que se le asignan. Modelamos allocation como `Map<agentId, itemId>`
|
|
13
|
+
// para el caso single-unit (cada item a un solo agente). Para
|
|
14
|
+
// combinatorial auctions se generaliza con bundles, pero el `MechanismOutcome`
|
|
15
|
+
// público mantiene el tipo Map<string,string> según contrato.
|
|
16
|
+
//
|
|
17
|
+
// Los pagos son no-negativos cuando el mechanism es individually
|
|
18
|
+
// rational; aceptamos negativos en VCG con bundles porque las pivots
|
|
19
|
+
// pueden compensar (típicamente VCG cobra >= 0 si la valuation es
|
|
20
|
+
// monotónica, lo que asumimos por construcción de ejemplos).
|
|
21
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/reasoning/mechanism-design/types.ts"],"names":[],"mappings":";AAAA,+DAA+D;AAC/D,uCAAuC;AACvC,+DAA+D;AAC/D,EAAE;AACF,kEAAkE;AAClE,uEAAuE;AACvE,iEAAiE;AACjE,4BAA4B;AAC5B,EAAE;AACF,sEAAsE;AACtE,sEAAsE;AACtE,8DAA8D;AAC9D,+EAA+E;AAC/E,8DAA8D;AAC9D,EAAE;AACF,iEAAiE;AACjE,qEAAqE;AACrE,kEAAkE;AAClE,6DAA6D"}
|