All Downloads are FREE. Search and download functionalities are using the official Maven repository.

es.uam.eps.ir.relison.diffusion.selections.LimitedCountThresholdSelectionMechanism Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (C) 2020 Information Retrieval Group at Universidad Autónoma
 * de Madrid, http://ir.ii.uam.es
 * 
 *  This Source Code Form is subject to the terms of the Mozilla Public
 *  License, v. 2.0. If a copy of the MPL was not distributed with this
 *  file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */
package es.uam.eps.ir.relison.diffusion.selections;

import es.uam.eps.ir.relison.diffusion.data.Data;
import es.uam.eps.ir.relison.diffusion.data.PropagatedInformation;
import es.uam.eps.ir.relison.diffusion.simulation.SimulationState;
import es.uam.eps.ir.relison.diffusion.simulation.UserState;
import es.uam.eps.ir.relison.graph.edges.EdgeOrientation;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Selection mechanism that only propagates those received pieces which have been received (at least) a fixed
 * number of times. It propagates any information piece that the user has received, from, at least, a
 * given proportion of his neighbors.
 *
 * 

* Reference: D. Kempe, J. Kleinberg, and E. Tardos. Maximizing the spread of influence through a social network, KDD 2003, pp. 137–146 (2003). *

* * It fixes the (maximum) number of received pieces to propagate. * * @author Javier Sanz-Cruzado ([email protected]) * @author Pablo Castells ([email protected]) * * @param type of the users. * @param type of the information pieces. * @param

type of the parameters. */ public class LimitedCountThresholdSelectionMechanism extends CountSelectionMechanism { /** * Number of users that transmit an information piece before a user chooses to share it. */ private final int threshold; /** * Orientation for selecting the neighborhood. */ private final EdgeOrientation orientation; /** * Constructor. * @param numOwn number of own pieces to propagate. * @param numRec maximum number of received pieces to propagate. * @param threshold number of users that transmit an information piece before a user chooses to share it. * @param orientation orientation for selecting the number of neighbors to consider. */ public LimitedCountThresholdSelectionMechanism(int numOwn, int numRec, int threshold, EdgeOrientation orientation) { super(numOwn, numRec); this.threshold = threshold; this.orientation = orientation; } /** * * @param numOwn number of own pieces to propagate. * @param numRec maximum number of received pieces to propagate. * @param threshold number of users that transmit an information piece before a user chooses to share it. * @param orientation orientation for selecting the number of neighbors to consider. * @param numRepr number of pieces to repropagate. */ public LimitedCountThresholdSelectionMechanism(int numOwn, int numRec, int threshold, EdgeOrientation orientation, int numRepr) { super(numOwn, numRec, numRepr); this.threshold = threshold; this.orientation = orientation; } @Override protected List getReceivedInformation(UserState user, Data data, SimulationState state, int numIter, Long timestamp) { // We first obtain al the possible information to repropagate: int userId = data.getUserIndex().object2idx(user.getUserId()); List aux = new ArrayList<>(); // Select the pieces to propagate. user.getReceivedInformation().forEach(info -> { if(info.getTimes() >= this.threshold) { aux.add(new PropagatedInformation(info.getInfoId(), numIter, userId)); } }); // We do randomly select the information pieces to propagate among the ones received earlier. return this.getPropagatedInformation(userId, this.getNumReceived(), numIter, aux); } }